-
Notifications
You must be signed in to change notification settings - Fork 10
Feat/benchmark query expansion #56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
7ee11f2
7425998
846d169
bd8550d
5f5aae9
2f14e59
16c684a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,43 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import asyncio | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from vektori.storage.memory import MemoryBackend | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from vektori.ingestion.extractor import FactExtractor | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from vektori.models.base import LLMProvider, EmbeddingProvider | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| class MockEmbedder(EmbeddingProvider): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @property | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def dimension(self): return 2 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| async def embed(self, text): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if "hate" in text: return [0.5, -0.5] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return [0.5, 0.5] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| async def embed_batch(self, texts): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return [await self.embed(t) for t in texts] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| class MockLLM(LLMProvider): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| async def generate(self, prompt, max_tokens=1000, **kwargs): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| pass | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| async def test(): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| db = MemoryBackend() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| await db.initialize() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| embedder = MockEmbedder() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| llm = MockLLM() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| extractor = FactExtractor(db, embedder, llm) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # insert first fact | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| await extractor._process_facts( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| [{"text": "User loves apples"}], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| session_id="s1", user_id="u1", agent_id=None, conversation="User: I love apples" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # insert second fact | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| await extractor._process_facts( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| [{"text": "User hates apples"}], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| session_id="s2", user_id="u1", agent_id=None, conversation="User: Actually I hate apples" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| facts = await db.get_active_facts("u1") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| print("Active facts count:", len(facts)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for f in facts: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| print(f["text"]) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| asyncio.run(test()) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This harness never verifies the new contradiction path.
Suggested direction class MockLLM(LLMProvider):
async def generate(self, prompt, max_tokens=1000, **kwargs):
- pass
+ if "loves apples" in prompt and "hates apples" in prompt:
+ old_id = prompt.split("- [")[1].split("]")[0]
+ return f'{{"supersedes_id": "{old_id}"}}'
+ return '{"supersedes_id": null}'
@@
- facts = await db.get_active_facts("u1")
- print("Active facts count:", len(facts))
- for f in facts:
- print(f["text"])
-
-asyncio.run(test())
+ facts = await db.get_active_facts("u1")
+ assert [f["text"] for f in facts] == ["User hates apples"]📝 Committable suggestion
Suggested change
🧰 Tools🪛 GitHub Actions: CI[warning] 25-25: Ruff W293: Blank line contains whitespace. Remove whitespace from blank line. [warning] 31-31: Ruff W293: Blank line contains whitespace. Remove whitespace from blank line. [warning] 37-37: Ruff W293: Blank line contains whitespace. Remove whitespace from blank line. 🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,39 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import asyncio | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from vektori.storage.memory import MemoryBackend | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from vektori.ingestion.extractor import FactExtractor | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from vektori.models.base import LLMProvider, EmbeddingProvider | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import logging | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| logging.basicConfig(level=logging.DEBUG) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| class MockEmbedder(EmbeddingProvider): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @property | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def dimension(self): return 2 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| async def embed(self, text): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if "hate" in text: return [0.5, 0.4] # High similarity to trigger check | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return [0.5, 0.5] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| async def embed_batch(self, texts): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return [await self.embed(t) for t in texts] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| class MockLLM(LLMProvider): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| async def generate(self, prompt, max_tokens=1000, **kwargs): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if "loves apples" in prompt and "hates apples" in prompt: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| old_id = prompt.split("- [")[1].split("]")[0] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return f'{{"supersedes_id": "{old_id}"}}' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return "{}" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| async def test(): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| db = MemoryBackend() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| await db.initialize() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| embedder = MockEmbedder() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| llm = MockLLM() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| extractor = FactExtractor(db, embedder, llm) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| await extractor._process_facts([{"text": "User loves apples"}], "s1", "u1", None, "") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| await extractor._process_facts([{"text": "User hates apples"}], "s2", "u1", None, "") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| facts = await db.get_active_facts("u1") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| print("Active facts count:", len(facts)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for f in facts: print("-", f["text"]) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| asyncio.run(test()) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is still a demo script, not an automated test. The module executes immediately and logs the outcome instead of asserting it. If supersession stops working, nothing here will fail the suite. Suggested direction async def test():
@@
facts = await db.get_active_facts("u1")
- print("Active facts count:", len(facts))
- for f in facts: print("-", f["text"])
-
-asyncio.run(test())
+ assert [f["text"] for f in facts] == ["User hates apples"]📝 Committable suggestion
Suggested change
🧰 Tools🪛 GitHub Actions: CI[warning] 31-31: Ruff W293: Blank line contains whitespace. Remove whitespace from blank line. [warning] 34-34: Ruff W293: Blank line contains whitespace. Remove whitespace from blank line. [error] 37-37: Ruff E701: Multiple statements on one line (colon). 🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| import asyncio | ||
| from vektori.storage.memory import MemoryBackend | ||
| from vektori.ingestion.extractor import FactExtractor | ||
| from vektori.models.base import LLMProvider, EmbeddingProvider | ||
|
|
||
| class MockEmbedder(EmbeddingProvider): | ||
| @property | ||
| def dimension(self): return 2 | ||
| async def embed(self, text): | ||
| if "hate" in text: return [0.5, 0.4] # Give sim around 0.8 to test LLM | ||
| return [0.5, 0.5] | ||
| async def embed_batch(self, texts): | ||
| return [await self.embed(t) for t in texts] | ||
|
|
||
| class MockLLM(LLMProvider): | ||
| async def generate(self, prompt, max_tokens=1000, **kwargs): | ||
| if "contradict" in prompt.lower(): | ||
| # If it has "hate", it contradicts the "love" one | ||
| if "hates apples" in prompt and "loves apples" in prompt: | ||
| return '{"contradicts": "1"}' | ||
| return '{"contradicts": null}' | ||
| pass | ||
|
|
||
| async def test(): | ||
| db = MemoryBackend() | ||
| await db.initialize() | ||
| embedder = MockEmbedder() | ||
| llm = MockLLM() | ||
| extractor = FactExtractor(db, embedder, llm) | ||
|
|
||
| # Needs actual logic in Extractor... | ||
|
|
||
| asyncio.run(test()) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The mock contract no longer matches the extractor.
Minimal fix class MockLLM(LLMProvider):
async def generate(self, prompt, max_tokens=1000, **kwargs):
if "contradict" in prompt.lower():
if "hates apples" in prompt and "loves apples" in prompt:
- return '{"contradicts": "1"}'
- return '{"contradicts": null}'
- pass
+ old_id = prompt.split("- [")[1].split("]")[0]
+ return f'{{"supersedes_id": "{old_id}"}}'
+ return '{"supersedes_id": null}'
+ return '{"supersedes_id": null}'🧰 Tools🪛 GitHub Actions: CI[error] 29-29: Ruff F841: Local variable [warning] 30-30: Ruff W293: Blank line contains whitespace. Remove whitespace from blank line. [warning] 32-32: Ruff W293: Blank line contains whitespace. Remove whitespace from blank line. 🤖 Prompt for AI Agents |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| import asyncio | ||
| from vektori import Vektori | ||
|
|
||
| async def test(): | ||
| v = Vektori(storage_backend="memory") | ||
| await v._ensure_initialized() | ||
| # Mock LLM to just return a synthesis fact | ||
| async def mock_gen(*args, **kwargs): | ||
| return '{"facts": [{"text": "User loves fruit overall."}]}' | ||
| async def mock_emb(*args, **kwargs): | ||
| return [[0.1, 0.2]] | ||
| v.llm.generate = mock_gen | ||
| v.embedder.embed_batch = mock_emb | ||
|
|
||
| # add dummy facts so synthesize triggers (needs >=5 base facts) | ||
| for i in range(5): | ||
| await v.db.insert_fact(f"fact {i}", [0.1, 0.2], "u1", confidence=1.0) | ||
|
|
||
| n = await v.synthesize("u1") | ||
| print("New synthesized facts:", n) | ||
| facts = await v.db.get_active_facts("u1", limit=100) | ||
| for f in facts: | ||
| if f.get("metadata", {}).get("source") == "synthesis": | ||
| print("Synthesized:", f["text"]) | ||
|
|
||
| asyncio.run(test()) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Convert this import-time script into an actual test. This module executes during import and only prints results, so synthesis regressions won’t fail CI. Please assert on the synthesized count and stored facts instead of relying on Suggested direction-async def test():
+async def test_synthesize_inserts_fact():
v = Vektori(storage_backend="memory")
await v._ensure_initialized()
@@
n = await v.synthesize("u1")
- print("New synthesized facts:", n)
+ assert n == 1
facts = await v.db.get_active_facts("u1", limit=100)
- for f in facts:
- if f.get("metadata", {}).get("source") == "synthesis":
- print("Synthesized:", f["text"])
-
-asyncio.run(test())
+ synthesized = [
+ f["text"]
+ for f in facts
+ if f.get("metadata", {}).get("source") == "synthesis"
+ ]
+ assert synthesized == ["User loves fruit overall."]🧰 Tools🪛 GitHub Actions: CI[warning] 14-14: Ruff W293: Blank line contains whitespace. Remove whitespace from blank line. [warning] 18-18: Ruff W293: Blank line contains whitespace. Remove whitespace from blank line. [warning] 25-25: Ruff W293: Blank line contains whitespace. Remove whitespace from blank line. 🤖 Prompt for AI Agents |
||
Uh oh!
There was an error while loading. Please reload this page.