Fix ai-service Dockerfile: bake in drug_entities.json, override its path

This commit is contained in:
2026-08-10 10:35:13 +07:00
parent a4b8e1c4db
commit 60b4397032
51 changed files with 4302 additions and 2087 deletions
@@ -18,6 +18,9 @@ ROOT = Path(__file__).resolve().parents[3]
CHUNKS = ROOT / "ingestion/data/processed/chunks.jsonl"
PDF = ROOT / "ingestion/data/raw/duoc-thu-quoc-gia-viet-nam-2018.pdf"
MIGRATION = Path(__file__).resolve().parents[1] / "migrations/001_rag_retrieval_trace.sql"
CONVERSATION_MIGRATION = (
Path(__file__).resolve().parents[1] / "migrations/002_rag_conversation_turn.sql"
)
class _PlumbingEmbedder:
@@ -131,6 +134,38 @@ def test_real_postgres_migration_insert_and_read_back():
assert stored.citations[0]["printed_page_start"] == 101
def test_real_postgres_conversation_store_round_trip():
"""F-08's durable conversation history against a real Postgres, not a
fake — proves `append`/`recent` actually persist and window correctly,
the concrete capability this whole feature exists to add over the
in-process dict it replaces."""
from adapters.postgres import PostgresConversationStore
store = PostgresConversationStore(
"postgresql://duoc_thu:duoc_thu@localhost:5432/duoc_thu"
)
store.migrate(CONVERSATION_MIGRATION)
conversation_id = f"test-{uuid.uuid4()}"
store.append(conversation_id, "Người dùng: liều paracetamol")
store.append(conversation_id, "Trợ lý: cần biết đối tượng")
store.append(conversation_id, "Người dùng: người lớn")
assert store.recent(conversation_id, limit=10) == [
"Người dùng: liều paracetamol",
"Trợ lý: cần biết đối tượng",
"Người dùng: người lớn",
]
# Windowing at read time: the oldest line falls outside a limit=2 read.
assert store.recent(conversation_id, limit=2) == [
"Trợ lý: cần biết đối tượng",
"Người dùng: người lớn",
]
# A conversation_id that was never written to reads back empty, not an
# error — the same "no history yet" case a fresh conversation hits live.
assert store.recent(f"never-seen-{uuid.uuid4()}", limit=10) == []
class _FakeJsonLlm:
"""Deterministic stand-in for the Bedrock Converse generator. Satisfies
both `JsonLlm` (query understanding) and `AnswerGenerator` (answer +