feat: implement RAG capabilities and Context Pane integration

- Add RAG capabilities using LlamaIndex and ChromaDB
- Implement RAGManager for PHB indexing and retrieval
- Integrate RAG pipeline into orchestrator to trigger queries based on extracted entities
- Update TUI to include a 3-column layout with a real-time Context Pane
- Define ContextUpdate data models in src/llm/models.py
- Update requirements.txt with new dependencies
This commit is contained in:
2026-05-26 22:07:12 -07:00
parent f4c98fb2b9
commit 954f2f50d8
6 changed files with 281 additions and 5 deletions
+35 -2
View File
@@ -17,13 +17,19 @@ class ConfirmationApp(App):
}
#left-pane {
width: 40%;
width: 30%;
border: solid;
padding: 1;
}
#middle-pane {
width: 30%;
border: solid;
padding: 1;
}
#right-pane {
width: 60%;
width: 40%;
border: solid;
padding: 1;
layout: vertical;
@@ -61,10 +67,12 @@ class ConfirmationApp(App):
self,
result: Optional[ExtractionResult] = None,
proposal_queue: Optional[asyncio.Queue] = None,
context_queue: Optional[asyncio.Queue] = None,
):
super().__init__()
self.result = result
self.proposal_queue = proposal_queue
self.context_queue = context_queue
self.pending_updates: List[Union[LoreUpdate, CharacterStateUpdate]] = []
if result:
@@ -81,6 +89,10 @@ class ConfirmationApp(App):
DataTable(id="update-table"),
id="left-pane",
),
Vertical(
Static("No context available", id="context-pane"),
id="middle-pane",
),
Vertical(
Vertical(
Label("Details:", id="details-label"),
@@ -132,6 +144,9 @@ class ConfirmationApp(App):
if self.proposal_queue:
self.run_worker(self.poll_proposal_queue, thread=False)
if self.context_queue:
self.run_worker(self.poll_context_queue, thread=False)
async def poll_proposal_queue(self) -> None:
"""
Background worker that polls the proposal queue for new extraction results.
@@ -147,6 +162,24 @@ class ConfirmationApp(App):
# Log error but keep the worker running
self.log(f"Error polling proposal queue: {e}")
async def poll_context_queue(self) -> None:
"""
Background worker that polls the context queue for new RAG updates.
"""
while True:
try:
update = await self.context_queue.get()
context_pane = self.query_one("#context-pane", Static)
# Format the update for display
display_text = f"Query: {update.query}\nSource: {update.source}\n\n{update.snippet}"
context_pane.update(display_text)
if hasattr(self.context_queue, "task_done"):
self.context_queue.task_done()
except Exception as e:
self.log(f"Error polling context queue: {e}")
def add_result(self, result: ExtractionResult) -> None:
"""
Adds results from the LLM processor to the TUI table.