fix(core): preserve adapter command contracts
This commit is contained in:
+8
-13
@@ -255,7 +255,7 @@ def memory_vector_record_for_decision(
|
||||
|
||||
|
||||
def save_one_memory(
|
||||
records: list[MemoryRecord], decision_seq: int, *, writer, embedder
|
||||
records: list[MemoryRecord], decision_seq: int, *, store, embedder
|
||||
) -> int:
|
||||
"""Targeted one-row upsert of a promoted decision to pgvector via the writer key
|
||||
(spec D11). This is NOT a full vectorstore resync: it embeds and pushes a single
|
||||
@@ -267,27 +267,22 @@ def save_one_memory(
|
||||
the writer's existing_vector_hashes; the embedding (Ollama round-trip) and the
|
||||
upsert are skipped when the content is unchanged. Idempotent by construction.
|
||||
|
||||
`writer` is a VectorRestClient (writer key); `embedder` an embeddings client.
|
||||
`store` is the configured writable VectorStore; `embedder` an embeddings client.
|
||||
The destructive cleanup (sync's delete-stale step) is intentionally absent: it
|
||||
remains a server-side-only operation via the direct vectordb connection.
|
||||
"""
|
||||
from tht.vectorstore.rest_writer import pack_metadata
|
||||
from tht.ports.vector import VectorWriteRecord
|
||||
from tht.vectorstore.store import content_hash
|
||||
|
||||
record = memory_vector_record_for_decision(records, decision_seq)
|
||||
if record is None:
|
||||
return 0
|
||||
new_hash = content_hash(record.content)
|
||||
existing = writer.existing_hashes("memory", ["memory"])
|
||||
existing = store.existing_hashes("memory", ["memory"])
|
||||
if existing.get(record.id) == new_hash:
|
||||
return 0 # unchanged: skip embedding + upsert
|
||||
embedding = embedder.embed_documents([record.content])[0]
|
||||
row = {
|
||||
"record_key": record.id,
|
||||
"kind": record.kind,
|
||||
"content_hash": new_hash,
|
||||
"metadata": pack_metadata(record),
|
||||
"embedding": embedding,
|
||||
}
|
||||
return writer.upsert_records("memory", [row])
|
||||
|
||||
return store.upsert(
|
||||
"memory",
|
||||
[VectorWriteRecord(record=record, embedding=embedding, content_hash=new_hash)],
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user