Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

Fix/add es num_candidates (#9225)

Jyong80b62d50f5cc
diff --git a/api/core/rag/datasource/vdb/elasticsearch/elasticsearch_vector.py b/api/core/rag/datasource/vdb/elasticsearch/elasticsearch_vector.py
index 8d578551209..f585e12b2e9 100644
--- a/api/core/rag/datasource/vdb/elasticsearch/elasticsearch_vector.py
+++ b/api/core/rag/datasource/vdb/elasticsearch/elasticsearch_vector.py
@@ -1,5 +1,6 @@
import json
import logging
+import math
from typing import Any, Optional
from urllib.parse import urlparse
@@ -112,7 +113,8 @@ class ElasticSearchVector(BaseVector):
def search_by_vector(self, query_vector: list[float], **kwargs: Any) -> list[Document]:
top_k = kwargs.get("top_k", 10)
- knn = {"field": Field.VECTOR.value, "query_vector": query_vector, "k": top_k}
+ num_candidates = math.ceil(top_k * 1.5)
+ knn = {"field": Field.VECTOR.value, "query_vector": query_vector, "k": top_k, "num_candidates": num_candidates}
results = self._client.search(index=self._collection_name, knn=knn, size=top_k)