Upsert
Write documents to both stores in one call.
Each document carries an id, either text (which gets embedded) or a
vector, and optional metadata. dynavec splits metadata: a small filterable subset
goes to S3 Vectors, the full copy plus text goes to DynamoDB.
from dynavec import Document
db.upsert([
Document(id="1", text="apple pie recipe", metadata={"cat": "food", "rating": 5}),
Document(id="2", text="rocket launch schedule", metadata={"cat": "space"}),
], namespace="kb", auto_metadata=True)
The metadata switch
- You provide metadata — stored verbatim.
auto_metadata=True— dynavec also derivescreated_at,content_hash,word_count,char_count. Your keys win on conflict.
Re-upserting the same id overwrites it. Writes to the two stores run in parallel; see
Concurrency. To change part of a document, use
update.
Document size limit
Each document's text and metadata are stored as one DynamoDB item, which DynamoDB caps at 400 KB.
upsert() and update() check every document's size before writing anything, and
raise ItemTooLargeError (with doc_id, namespace,
size_bytes, and limit_bytes) if one is too big. The whole call fails, so S3 Vectors
and DynamoDB never end up with half a batch.
from dynavec import ItemTooLargeError
from dynavec.ingest import chunk_text
try:
db.upsert([Document(id="manual", text=long_text)], namespace="kb")
except ItemTooLargeError as err:
print(err.doc_id, err.size_bytes, err.limit_bytes)
db.upsert(
[Document(id=f"manual#chunk{i}", text=chunk)
for i, chunk in enumerate(chunk_text(long_text, chunk_size=2000))],
namespace="kb",
)