Principle:24kchengYe MemoMind Batch Database Storage
| Knowledge Sources | |
|---|---|
| Domains | Database, Data_Storage |
| Last Updated | 2026-10-28 00:00 GMT |
Overview
Technique that inserts multiple facts into a PostgreSQL database in a single batch operation using `unnest` for column arrays, minimizing round-trips and enabling transactional atomicity.
Description
Inserting facts one by one requires N database round-trips for N facts. Batch storage uses PostgreSQL's `unnest` to pass all column values as arrays in a single query, then `INSERT ... SELECT FROM unnest(...)` to insert all rows atomically.
This provides:
- Performance: one query instead of N
- Atomicity: all facts in a batch succeed or fail together
- Search vector population: the query also computes the BM25 search vector (via `tokenize` for VectorChord or `GENERATED ALWAYS` for native PostgreSQL)
The stored facts include text, embedding vector, temporal fields (event_date, occurred_start, occurred_end, mentioned_at), context, fact_type, confidence_score, metadata, chunk_id, document_id, tags, observation_scopes, and text_signals (entity names + date tokens for enriched BM25 indexing).
Usage
Use this principle when storing multiple facts per retain operation. It is the persistence layer of the retain pipeline, called after fact extraction, embedding, and entity resolution.
Theoretical Basis
-- Abstract batch insert (simplified SQL)
WITH input_data AS (
SELECT * FROM unnest(
$2::text[], $3::vector[], $4::timestamptz[], ...
) AS t(text, embedding, event_date, ...)
)
INSERT INTO memory_units (bank_id, text, embedding, ...)
SELECT $1, text, embedding, ...
FROM input_data
RETURNING id
The `text_signals` column enriches BM25 indexing by concatenating entity names and date tokens with the fact text, so searches for entity names or dates match even when the fact text doesn't contain them literally.