Skip to content

Hypergraph is more powerful. Transform unstructured text into structured knowledge with LLMs. Graphs, hypergraphs, and spatio-temporal extractions — with one command.

fix: forward source/tag scope through Cog_RAG.chat

Frankie-Xu4ff75e63f0b8
diff --git a/hyperextract/methods/rag/cog_rag.py b/hyperextract/methods/rag/cog_rag.py
index e174f9c..da9a12c 100644
--- a/hyperextract/methods/rag/cog_rag.py
+++ b/hyperextract/methods/rag/cog_rag.py
@@ -429,9 +429,23 @@ class Cog_RAG:
return {"themes": themes, "entities": entities}
- def chat(self, query: str, top_k_themes: int = 3, top_k_entities: int = 3):
+ def chat(
+ self,
+ query: str,
+ top_k_themes: int = 3,
+ top_k_entities: int = 3,
+ *,
+ source_ids: list[str] | None = None,
+ tags: list[str] | None = None,
+ ):
"""Generate an answer using context from both layers."""
- results = self.search(query, top_k_themes, top_k_entities)
+ results = self.search(
+ query,
+ top_k_themes,
+ top_k_entities,
+ source_ids=source_ids,
+ tags=tags,
+ )
context_parts = []
if results["themes"]:
diff --git a/tests/methods/test_search_scope_forwarding.py b/tests/methods/test_search_scope_forwarding.py
index c482eb9..3c627a4 100644
--- a/tests/methods/test_search_scope_forwarding.py
+++ b/tests/methods/test_search_scope_forwarding.py
@@ -79,6 +79,23 @@ class TestCogRagScope:
assert calls["edges"] == {"source_ids": ["s1"], "tags": ["t1"]}
assert calls["nodes"] == {"source_ids": ["s1"], "tags": ["t1"]}
+ def test_chat_forwards_scope_to_search(self):
+ cog = Cog_RAG.__new__(Cog_RAG)
+ seen = {}
+
+ def _search(query, top_k_themes=3, top_k_entities=3, **kwargs):
+ seen["kwargs"] = kwargs
+ return {"themes": [], "entities": []}
+
+ cog.search = _search
+ from langchain_core.runnables import RunnableLambda
+
+ cog.llm = RunnableLambda(lambda _: "ok")
+
+ cog.chat("q", source_ids=["s1"], tags=["t1"])
+
+ assert seen["kwargs"] == {"source_ids": ["s1"], "tags": ["t1"]}
+
def test_cog_rag_uses_hypergraph_layers(self):
"""ThemeSchema participates in the theme layer's hyperedge schema."""
assert issubclass(ThemeSchema, object)