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 the issue of repeated escaping of quotes in hit test (#13477)

liuzhenghua47a64610ca14
diff --git a/api/core/rag/datasource/retrieval_service.py b/api/core/rag/datasource/retrieval_service.py
index 3a8200bc7b5..927df0efc42 100644
--- a/api/core/rag/datasource/retrieval_service.py
+++ b/api/core/rag/datasource/retrieval_service.py
@@ -1,3 +1,4 @@
+import json
import threading
from typing import Optional
@@ -171,7 +172,7 @@ class RetrievalService:
vector = Vector(dataset=dataset)
documents = vector.search_by_vector(
- cls.escape_query_for_search(query),
+ query,
search_type="similarity_score_threshold",
top_k=top_k,
score_threshold=score_threshold,
@@ -250,7 +251,7 @@ class RetrievalService:
@staticmethod
def escape_query_for_search(query: str) -> str:
- return query.replace('"', '\\"')
+ return json.dumps(query).strip('"')
@staticmethod
def format_retrieval_documents(documents: list[Document]) -> list[RetrievalSegments]:
diff --git a/api/services/hit_testing_service.py b/api/services/hit_testing_service.py
index e9176fc1c60..f8c1c1d297a 100644
--- a/api/services/hit_testing_service.py
+++ b/api/services/hit_testing_service.py
@@ -47,7 +47,7 @@ class HitTestingService:
all_documents = RetrievalService.retrieve(
retrieval_method=retrieval_model.get("search_method", "semantic_search"),
dataset_id=dataset.id,
- query=cls.escape_query_for_search(query),
+ query=query,
top_k=retrieval_model.get("top_k", 2),
score_threshold=retrieval_model.get("score_threshold", 0.0)
if retrieval_model["score_threshold_enabled"]