Repository navigation
fix(indexer): wire contextualization into hexagonal pool #524
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
hedhoud
merged 4 commits into
refactor/hexagonal
from
fix/contextualization-indexer-wiring
Jun 19, 2026
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
a0b3df3
fix(indexer): wire contextualization into pool
hedhoud 37649d7
feat(indexer): rate-limit chunk contextualization via the distributed…
Ahmath-Gadji 8aa7249
fix(presets): drive default contextualization from CONTEXTUAL_RETRIEVAL
Ahmath-Gadji 77769ab
fix(presets): preserve admin-managed default preset
hedhoud 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
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
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,57 @@ | ||
| from __future__ import annotations | ||
|
|
||
| import pytest | ||
| from core.indexing.contextualize import ChunkContextualizer | ||
| from core.models.chunk import Chunk | ||
|
|
||
|
|
||
| class DictLLM: | ||
| async def chat(self, messages, **kwargs): | ||
| return {"choices": [{"message": {"content": "document-level context"}}]} | ||
|
|
||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_contextualizer_accepts_openai_style_chat_response(): | ||
| contextualizer = ChunkContextualizer(DictLLM(), "System prompt") | ||
|
|
||
| result = await contextualizer.contextualize([Chunk(id="c1", text="chunk body", partition="p")]) | ||
|
|
||
| assert result[0].context == "document-level context" | ||
| assert result[0].content == "chunk body" | ||
|
|
||
|
|
||
| class _GatingLLM: | ||
| """LLM stub that records whether the LLM gate was held during ``chat``.""" | ||
|
|
||
| def __init__(self, gate_held: list[bool]): | ||
| self._gate_held = gate_held | ||
|
|
||
| async def chat(self, messages, **kwargs): | ||
| self._gate_held.append(_TrackingGate.depth > 0) | ||
| return {"choices": [{"message": {"content": "ctx"}}]} | ||
|
|
||
|
|
||
| class _TrackingGate: | ||
| """Async context manager standing in for the distributed LLM semaphore.""" | ||
|
|
||
| depth = 0 | ||
|
|
||
| async def __aenter__(self): | ||
| type(self).depth += 1 | ||
| return self | ||
|
|
||
| async def __aexit__(self, *exc): | ||
| type(self).depth -= 1 | ||
|
|
||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_contextualizer_holds_llm_semaphore_around_chat(): | ||
| _TrackingGate.depth = 0 | ||
| gate_held: list[bool] = [] | ||
| contextualizer = ChunkContextualizer(_GatingLLM(gate_held), "System prompt", llm_semaphore=_TrackingGate()) | ||
|
|
||
| await contextualizer.contextualize([Chunk(id="c1", text="chunk body", partition="p")]) | ||
|
|
||
| # The injected gate was entered for the chat call and released afterwards. | ||
| assert gate_held == [True] | ||
| assert _TrackingGate.depth == 0 |
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.