feat: index semantic records in qdrant
This commit is contained in:
@@ -7,19 +7,28 @@ pgvector as a one-row upsert. This test pins the pure core of that behavior:
|
||||
- the writer.upsert_records is called once with a single row
|
||||
- writer.sync is NEVER called (that is the full-resync path)
|
||||
"""
|
||||
from datetime import datetime
|
||||
from datetime import UTC, datetime
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
from tht.adapters.vector.qdrant import point_id
|
||||
from tht.memory import MemoryRecord, memory_vector_record_for_decision, save_one_memory
|
||||
from tht.vectorstore.records import qdrant_payload
|
||||
|
||||
|
||||
def _record(seq: int = 7, **kw) -> MemoryRecord:
|
||||
base = dict(
|
||||
id="mem-0007", ts=datetime(2025, 1, 1), session_id="s1", decision_seq=seq,
|
||||
type="concept_clarified", subject="paziente attivo",
|
||||
detail="flag_attivo = TRUE", rationale="r",
|
||||
question_context="dammi i pazienti", tables=[], concepts=["paziente attivo"],
|
||||
)
|
||||
base = {
|
||||
"id": "mem-0007",
|
||||
"ts": datetime(2025, 1, 1, tzinfo=UTC),
|
||||
"session_id": "s1",
|
||||
"decision_seq": seq,
|
||||
"type": "concept_clarified",
|
||||
"subject": "paziente attivo",
|
||||
"detail": "flag_attivo = TRUE",
|
||||
"rationale": "r",
|
||||
"question_context": "dammi i pazienti",
|
||||
"tables": [],
|
||||
"concepts": ["paziente attivo"],
|
||||
}
|
||||
base.update(kw)
|
||||
return MemoryRecord(**base)
|
||||
|
||||
@@ -85,3 +94,29 @@ def test_save_one_uses_writer_key_for_upsert():
|
||||
save_one_memory(records, decision_seq=7, store=writer, embedder=embedder)
|
||||
# one upsert call, single row, table=memory
|
||||
assert writer.upsert.call_count == 1
|
||||
|
||||
|
||||
def test_save_one_preserves_semantic_point_identity_fields():
|
||||
records = [_record(seq=7)]
|
||||
writer = MagicMock()
|
||||
writer.existing_hashes.return_value = {}
|
||||
writer.upsert.return_value = 1
|
||||
embedder = MagicMock()
|
||||
embedder.embed_documents.return_value = [[0.0] * 4]
|
||||
|
||||
save_one_memory(records, decision_seq=7, store=writer, embedder=embedder)
|
||||
|
||||
row = writer.upsert.call_args.args[1][0]
|
||||
payload = qdrant_payload(
|
||||
row.record,
|
||||
content_hash=row.content_hash,
|
||||
workspace_id="psd-clinical",
|
||||
workspace_revision="a" * 40,
|
||||
)
|
||||
|
||||
assert point_id("psd-clinical", "memory", row.record.id) == point_id(
|
||||
"psd-clinical", "memory", "memory:mem-0007"
|
||||
)
|
||||
assert payload["kind"] == "memory"
|
||||
assert payload["workspace_id"] == "psd-clinical"
|
||||
assert payload["workspace_revision"] == "a" * 40
|
||||
|
||||
Reference in New Issue
Block a user