Add production condition retrieval smoke test

This commit is contained in:
2026-08-11 14:58:28 +07:00
parent 59e6ad2d0d
commit 7ebbe1f309
38 changed files with 3752 additions and 121 deletions
+37
View File
@@ -23,6 +23,10 @@ class RetrievalTrace:
created_at: datetime | None = None
class FeedbackTraceNotFound(LookupError):
"""The answer trace was never persisted, so feedback cannot be linked."""
class PostgresTraceRepository:
"""Opens a new connection per call — no pooling (F-09: a real pool, with
startup-time lifecycle, is a further improvement not made here).
@@ -102,6 +106,39 @@ class PostgresTraceRepository:
created_at=row[10],
)
def save_feedback(
self,
*,
trace_id: str,
rating: str,
comment: str | None,
conversation_id: str | None,
) -> str:
"""Create or replace one user's verdict for one persisted answer."""
import psycopg
feedback_id = str(uuid.uuid4())
with psycopg.connect(self._dsn, connect_timeout=5) as connection:
row = connection.execute(
"""
INSERT INTO rag_answer_feedback (
feedback_id, trace_id, conversation_id, rating, comment
)
SELECT %s, trace_id, %s, %s, %s
FROM rag_retrieval_trace WHERE trace_id = %s
ON CONFLICT (trace_id) DO UPDATE SET
conversation_id = EXCLUDED.conversation_id,
rating = EXCLUDED.rating,
comment = EXCLUDED.comment,
updated_at = now()
RETURNING feedback_id::text
""",
(feedback_id, conversation_id, rating, comment, trace_id),
).fetchone()
if row is None:
raise FeedbackTraceNotFound(trace_id)
return str(row[0])
class PostgresConversationStore:
"""Durable, cross-worker replacement for `RagAgent`'s in-process