-
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
Merged
Merged
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
7ee11f2
fix(retrieval): temporal decay & query expansion for benchmark
laxmanclo 7425998
fix(ingestion): LLM-based contradiction logic for negated facts (#26)
laxmanclo 846d169
feat: cross-session synthesis pass for aggregate memory (#10)
laxmanclo bd8550d
feat: add test for synthesis functionality with mock LLM
laxmanclo 5f5aae9
refactor: Separate syntheses layer from L0 facts and update locomo be…
laxmanclo 2f14e59
chore: fix ruff linting errors and remove duplicate methods
laxmanclo 16c684a
fix: stabilize benchmark query expansion
Alex-Hunterz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -43,7 +43,7 @@ env/ | |
| .coverage | ||
| htmlcov/ | ||
| .tox/ | ||
|
|
||
| /data | ||
| # Environment variables | ||
| .env | ||
| .env.local | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| import asyncio | ||
|
|
||
| from vektori.ingestion.extractor import FactExtractor | ||
| from vektori.models.base import EmbeddingProvider, LLMProvider | ||
| from vektori.storage.memory import MemoryBackend | ||
|
|
||
|
|
||
| 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()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| import asyncio | ||
| import logging | ||
|
|
||
| from vektori.ingestion.extractor import FactExtractor | ||
| from vektori.models.base import EmbeddingProvider, LLMProvider | ||
| from vektori.storage.memory import MemoryBackend | ||
|
|
||
| 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()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| import asyncio | ||
|
|
||
| from vektori.ingestion.extractor import FactExtractor | ||
| from vektori.models.base import EmbeddingProvider, LLMProvider | ||
| from vektori.storage.memory import MemoryBackend | ||
|
|
||
|
|
||
| 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() | ||
| _ = FactExtractor(db, embedder, llm) | ||
|
|
||
| # Needs actual logic in Extractor... | ||
|
|
||
| asyncio.run(test()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| 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) | ||
| syntheses = await v.db.search_syntheses([0.1, 0.2], "u1", limit=100) | ||
| for s in syntheses: | ||
| print("Synthesized:", s["text"]) | ||
|
|
||
| asyncio.run(test()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.