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: opensearch vector search falls back to keyword search (#20723)

jefferyvvv37c3283450c9
diff --git a/api/core/rag/datasource/vdb/opensearch/opensearch_vector.py b/api/core/rag/datasource/vdb/opensearch/opensearch_vector.py
index 6a6c2b73ef9..0abb3c0077e 100644
--- a/api/core/rag/datasource/vdb/opensearch/opensearch_vector.py
+++ b/api/core/rag/datasource/vdb/opensearch/opensearch_vector.py
@@ -184,7 +184,16 @@ class OpenSearchVector(BaseVector):
}
document_ids_filter = kwargs.get("document_ids_filter")
if document_ids_filter:
- query["query"] = {"terms": {"metadata.document_id": document_ids_filter}}
+ query["query"] = {
+ "script_score": {
+ "query": {"bool": {"filter": [{"terms": {Field.DOCUMENT_ID.value: document_ids_filter}}]}},
+ "script": {
+ "source": "knn_score",
+ "lang": "knn",
+ "params": {"field": Field.VECTOR.value, "query_value": query_vector, "space_type": "l2"},
+ },
+ }
+ }
try:
response = self._client.search(index=self._collection_name.lower(), body=query)