diff --git a/common/gsql/supportai/retrievers/GraphRAG_Community_Vector_Search.gsql b/common/gsql/supportai/retrievers/GraphRAG_Community_Vector_Search.gsql index 29594d8..46a433f 100644 --- a/common/gsql/supportai/retrievers/GraphRAG_Community_Vector_Search.gsql +++ b/common/gsql/supportai/retrievers/GraphRAG_Community_Vector_Search.gsql @@ -37,6 +37,10 @@ CREATE OR REPLACE DISTRIBUTED QUERY GraphRAG_Community_Vector_Search(LIST ACCUM s.@children += c POST-ACCUM @@verbose_info += ("community_level_"+to_string(i-1) -> s.@children); END; + start_chunks = vectorSearch({DocumentChunk.embedding}, query_vector, top_k); + extra_selected_comms = SELECT m FROM start_chunks:dc -(CONTAINS_ENTITY>)- Entity:v -(RESOLVES_TO>)- ResolvedEntity:r -(IN_COMMUNITY>)- Community:m; + selected_comms = selected_comms UNION extra_selected_comms; + IF with_doc THEN related_chunks = SELECT c FROM Content:c -()- DocumentChunk:dc -(CONTAINS_ENTITY>)- Entity:v -(RESOLVES_TO>)- ResolvedEntity:r -(IN_COMMUNITY>)- selected_comms:m ACCUM m.@context += c.text, m.@children += d diff --git a/graphrag/app/routers/supportai.py b/graphrag/app/routers/supportai.py index 4bba7dd..5c377eb 100644 --- a/graphrag/app/routers/supportai.py +++ b/graphrag/app/routers/supportai.py @@ -238,6 +238,8 @@ def search( query.method_params["with_doc"], query.method_params["verbose"], ) + else: + raise Exception(f"Method {query.method} not implemented") return res diff --git a/graphrag/app/supportai/retrievers/CommunityRetriever.py b/graphrag/app/supportai/retrievers/CommunityRetriever.py index fab69d1..549c58d 100644 --- a/graphrag/app/supportai/retrievers/CommunityRetriever.py +++ b/graphrag/app/supportai/retrievers/CommunityRetriever.py @@ -62,6 +62,22 @@ def search(self, question, community_level: int, top_k: int = 5, similarity_thre }, usePost=True ) + + # Include similarity search results + if with_chunk or with_doc: + start_set = self._generate_start_set(questions, ["DocumentChunk"], top_k, similarity_threshold) + + self._check_query_install("Content_Similarity_Search") + resp = self.conn.runInstalledQuery( + "Content_Similarity_Search", + params = { + "json_list_vts": str(start_set), + "v_type": "DocumentChunk", + "verbose": verbose, + }, + usePost=True + ) + res[0]["final_retrieval"]["Similarity_Context"] = [resp[0]["final_retrieval"][x] for x in resp[0]["final_retrieval"]] else: query_vector = self._generate_embedding(question)