The cheapest index is the one you do not rebuild. For a logistics team chunking engineering documents into a vector index, use a short freshness window with change-driven updates for hot runbooks, and a scheduled snapshot for the long tail. That split keeps retrieval current without paying to re-embed unchanged pages. The decision is about staleness tolerance and write amplification, not which database has the flashiest demo.
Here is the compact choice matrix I use:
| Workload | Freshness window | Ingestion shape | Index-cost posture |
|---|---|---|---|
| Dispatch runbooks and carrier alerts | 5–15 minutes | Event-driven upserts | More writes, fewer stale answers |
| Stable integration guides | 6–24 hours | Batched snapshot | Fewer embedding and index operations |
| Audited procedures | Versioned release | Immutable snapshot plus rollback | Predictable, reviewable spend |
Freshness is a budget.
What should a Node.js retrieval pipeline do with freshness windows?
Treat a window as a contract. A document changed at 10:03 may be absent from search until the 10:15 batch; that is acceptable only if the answer layer shows the indexed timestamp. Do not hide the delay behind a vague “eventual consistency” label.
The retrieval-augmented generation (RAG) paper describes fetching passages and conditioning generation on them, which makes stale passages a correctness problem rather than a cosmetic one. In logistics, a superseded customs checklist can send a shipment down the wrong path. The index therefore needs two timestamps: sourceUpdatedAt from the repository and indexedAt from the vector store. Filter or warn when their difference exceeds the policy window.
I once started with a single nightly job because the cron expression looked tidy. It produced a 23-hour gap for a same-day carrier exception. The fix was not a faster database. It was classifying documents by operational risk and giving only the hot class a five-minute path. Small change. Big reduction in needless writes.
The cost model is mostly chunk churn
Embedding calls are only one line item. Re-indexing a 400-page manual can also mean deleting old vectors, writing new metadata, rebuilding filters, and running duplicate jobs after a retry. Measure four counters per batch: changed source bytes, chunks produced, embeddings requested, and vectors written. A rising chunks-per-change ratio usually means the splitter is unstable.
Use deterministic chunk IDs derived from a document revision and ordinal. If the same paragraph moves, you want an intentional replacement, not two live copies. Keep a tombstone stream for deleted pages; a missing file is not the same as an empty file.
The storage choice changes the operational work, but not this accounting. pgvector keeps the index close to Postgres and shifts capacity planning to your team. Pinecone is a managed vector service, so the team trades server operations for an external write and retention bill. Weaviate exposes a self-hosted or managed path with its own deployment decisions. None of those names removes the need to control chunk churn. Your mileage may vary with metadata filters and traffic shape, so benchmark with your document mix.
A change-aware ingestion loop in TypeScript
The loop below separates discovery from indexing. Discovery can read Git, an object store, or a documentation CMS; the indexer only receives a stable contract. That boundary makes it possible to test freshness without contacting a vendor.
type SourceDoc = { id: string; body: string; sourceUpdatedAt: string; risk: "hot" | "warm" | "cold"; }; type Chunk = SourceDoc & { chunkId: string; ordinal: number }; function windowMs(risk: SourceDoc["risk"]): number { if (risk === "hot") return 5 * 60_000; if (risk === "warm") return 6 * 60 * 60_000; return 24 * 60 * 60_000; } function shouldIndex(doc: SourceDoc, indexedAt: string | undefined, now = Date.now()): boolean { if (!indexedAt) return true; const age = now - Date.parse(indexedAt); return age >= windowMs(doc.risk) || Date.parse(doc.sourceUpdatedAt) > Date.parse(indexedAt); } async function ingest(doc: SourceDoc, indexedAt: string | undefined): Promise<void> { if (!shouldIndex(doc, indexedAt)) return; const chunks: Chunk[] = doc.body .split(/\n{2,}/) .filter(Boolean) .map((body, ordinal) => ({ ...doc, body, ordinal, chunkId: `${doc.id}:${doc.sourceUpdatedAt}:${ordinal}` })); await vectorIndex.replaceDocument(doc.id, chunks, { sourceUpdatedAt: doc.sourceUpdatedAt, indexedAt: new Date().toISOString() }); } The important operation is replaceDocument: it is an application-level contract that atomically retires a document's prior chunk set before exposing the new set. Implement that contract with a transaction where the backend supports one, or with a revision pointer and a garbage-collection pass where it does not. Retries must be idempotent; the same chunkId should produce the same logical record.
Clock skew can make a document look newer forever. Normalize timestamps to UTC and reject malformed values at ingestion. A partial batch can also create a mixed revision: half the chunks come from yesterday, half from today. Publish a revision marker only after every chunk succeeds, then have retrieval filter to the marker.
Deletion deserves its own test. Remove a page from the source, run the pipeline, and assert that a query cannot retrieve its old chunk. Also test a rename, a split-only edit, a failed embedding call, and a replayed event. I keep these as fixture tests in Node.js because they catch indexing semantics before production traffic does.
Watch p95 source-to-index latency, stale-hit rate, duplicate chunk rate, and vectors written per changed kilobyte. Alert on the stale-hit rate, not just worker health; a green queue can still serve old content.
When is a scheduled snapshot the better trade?
Choose snapshots for cold material that changes in coordinated releases, especially when reviewers need a reproducible corpus. They are easier to audit and roll back. The catch is that a snapshot is unsuitable when a same-hour policy change must affect answers; use the event-driven class there.
Choose the delta path when updates are small, frequent, and independently publishable. Stick with a snapshot when source systems cannot emit reliable change events or when rebuilding the complete corpus is cheaper than maintaining tombstones and revision state. The runner-up is not wrong; it is wrong for a different freshness promise.
Start with measured windows, then tighten only where stale-hit data justifies the extra index work. That keeps the architecture honest, the bill explainable, and the answer traceable to a specific document revision.