Commit b667cf1d authored by Kantz's avatar Kantz
Browse files

fixed retrieval

parent d93bc3e6
...@@ -196,5 +196,5 @@ def update_retrieval_context( ...@@ -196,5 +196,5 @@ def update_retrieval_context(
sources: list[Source], sources: list[Source],
) -> None: ) -> None:
merged = get_retrieval(sheet) + sources merged = get_retrieval(sheet) + sources
merged_sorted = sorted(merged, key=lambda item: item.score, reverse=True)[:8] merged_sorted = sorted(merged, key=lambda item: item.score, reverse=True)
set_sources(sheet, merged_sorted) set_sources(sheet, merged_sorted)
...@@ -4,7 +4,6 @@ from app.LLM_services import task_hint_LLM ...@@ -4,7 +4,6 @@ from app.LLM_services import task_hint_LLM
import app.config as config import app.config as config
from app.deterministic_services import ( from app.deterministic_services import (
context_store, context_store,
embedding_provider,
retrieval_store, retrieval_store,
task_catalog, task_catalog,
) )
...@@ -61,20 +60,14 @@ def _retrieve_context_for_task(state: base.ChatState, query_text: str) -> None: ...@@ -61,20 +60,14 @@ def _retrieve_context_for_task(state: base.ChatState, query_text: str) -> None:
return return
def _retrieve() -> dict: def _retrieve() -> dict:
embedder, cache_hit = embedding_provider.get_embedder() sources = retrieval_store.retrieve_for_subsections(
sources = retrieval_store.retrieve_with_subsections(
pg_url=config.get_postgres_url(), pg_url=config.get_postgres_url(),
embedder=embedder,
query=query_text,
subsection_refs=refs, subsection_refs=refs,
k=8,
expand_links=True,
) )
context_store.update_retrieval_context(state.sheet, sources) context_store.update_retrieval_context(state.sheet, sources)
return { return {
"subsection_refs": refs, "subsection_refs": refs,
"source_count": len(sources), "source_count": len(sources),
"embedder_cache_hit": cache_hit,
} }
base.log_timed_call( base.log_timed_call(
...@@ -98,7 +91,6 @@ def _on_bootstrap(state: base.ChatState, query_text: str) -> None: ...@@ -98,7 +91,6 @@ def _on_bootstrap(state: base.ChatState, query_text: str) -> None:
def _on_turn_logic(state: base.ChatState) -> None: def _on_turn_logic(state: base.ChatState) -> None:
_ensure_context_task_fields(state, state.last_user) _ensure_context_task_fields(state, state.last_user)
_retrieve_context_for_task(state, state.last_user)
# Antwort generieren # Antwort generieren
...@@ -126,22 +118,30 @@ def run_chat( ...@@ -126,22 +118,30 @@ def run_chat(
draft: str | None = None, draft: str | None = None,
selected_task: dict | None = None, selected_task: dict | None = None,
) -> dict: ) -> dict:
def _apply_selected_task(state: base.ChatState) -> None:
if not selected_task:
return
selected_file_id = str(selected_task.get("file_id", "")).strip()
selected_task_id = str(selected_task.get("task_id", "")).strip()
if selected_file_id and selected_task_id:
task_catalog.select_task_by_ids(
state.sheet,
selected_file_id,
selected_task_id,
)
def on_bootstrap(state: base.ChatState, query_text: str) -> None:
_apply_selected_task(state)
_on_bootstrap(state, query_text)
def on_turn_logic(state: base.ChatState) -> None: def on_turn_logic(state: base.ChatState) -> None:
if selected_task: _apply_selected_task(state)
selected_file_id = str(selected_task.get("file_id", "")).strip()
selected_task_id = str(selected_task.get("task_id", "")).strip()
if selected_file_id and selected_task_id:
task_catalog.select_task_by_ids(
state.sheet,
selected_file_id,
selected_task_id,
)
_on_turn_logic(state) _on_turn_logic(state)
return base.run_chat_common( return base.run_chat_common(
messages=messages, messages=messages,
draft=draft, draft=draft,
on_bootstrap=_on_bootstrap, on_bootstrap=on_bootstrap,
on_turn_logic=on_turn_logic, on_turn_logic=on_turn_logic,
on_build_reply=_on_build_reply, on_build_reply=_on_build_reply,
) )
...@@ -92,3 +92,13 @@ def retrieve_with_subsections( ...@@ -92,3 +92,13 @@ def retrieve_with_subsections(
expand_links=expand_links, expand_links=expand_links,
neighbor_expand=neighbor_expand, neighbor_expand=neighbor_expand,
) )
def retrieve_for_subsections(
pg_url: str,
subsection_refs: list[vector_store.SubsectionRef] | None = None,
) -> List[Source]:
return vector_store.load_children_for_subsections(
pg_url=pg_url,
subsection_refs=subsection_refs,
)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment