bitflicker64 commented on code in PR #412:
URL: https://github.com/apache/hugegraph-ai/pull/412#discussion_r4510944050
##########
hugegraph-llm/src/hugegraph_llm/operators/index_op/vector_index_query.py:
##########
@@ -25,17 +25,45 @@
class VectorIndexQuery:
- def __init__(self, vector_index: type[VectorStoreBase], embedding:
BaseEmbedding, topk: int = 3):
+ """Retrieve matching chunks from the chunk vector index.
+
+ ``vector_dis_threshold`` is forwarded to ``VectorStoreBase.search`` and
+ defaults to the ``VECTOR_DIS_THRESHOLD`` setting, the same contract as
+ :class:`SemanticIdQuery`. Stores rank by plain vector distance (FAISS
+ scores squared L2), so the threshold only prunes clearly-off matches;
+ ranking stays top-k and relevance is refined by the downstream
+ merge/rerank step.
+ """
+
+ def __init__(
+ self,
+ vector_index: type[VectorStoreBase],
+ embedding: BaseEmbedding,
+ topk: int = 3,
+ vector_dis_threshold: Optional[float] = None,
+ ):
self.embedding = embedding
self.topk = topk
+ self.vector_dis_threshold = (
+ huge_settings.vector_dis_threshold if vector_dis_threshold is None
else vector_dis_threshold
+ )
self.vector_index =
vector_index.from_name(embedding.get_embedding_dim(), huge_settings.graph_name,
"chunks")
def run(self, context: Dict[str, Any]) -> Dict[str, Any]:
query = context.get("query")
query_embedding = self.embedding.get_texts_embeddings([query])[0]
- # TODO: why set dis_threshold=2?
- results = self.vector_index.search(query_embedding, self.topk,
dis_threshold=2)
- # TODO: check format results
- context["vector_result"] = results
- log.debug("KNOWLEDGE FROM VECTOR:\n%s", "\n".join(rel for rel in
context["vector_result"]))
+ results = self.vector_index.search(query_embedding, self.topk,
dis_threshold=self.vector_dis_threshold)
Review Comment:
Important: every `/rag` flow and the Gradio demo pass 0.9 here, and on
squared-L2 stores (`FaissVectorIndex`, Milvus `L2`) that drops chunks with
cosine similarity at or below 0.55, which the old `2` kept, while the only way
back (`VECTOR_DIS_THRESHOLD=2.0`) also loosens `SemanticIdQuery` keyword
matching. Give chunk retrieval its own threshold setting defaulting to `2.0`,
so existing results stay the same and the two thresholds stay independent.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]