feat(store): attach document vectors after the write, not before it - #189
Merged
Merged
Conversation
When a document is not found in the namespace store, the code now returns a clear error instead of panicking or returning an ambiguous result. This improves robustness by ensuring callers can properly handle the absence of a document. Auto-committed-on: macbook Co-authored-by: Medulla <medulla@tinyhumans.ai>
Introduce a mechanism to defer document writes in the namespace store, allowing write operations to be batched and committed later. This change adds a new `documents_deferred` module and updates the memory trait and write gate to support deferred write patterns, improving performance for bulk write scenarios. Auto-committed-on: macbook Co-authored-by: Medulla <medulla@tinyhumans.ai>
Add a trace-level log message when a memory entry is stored without waiting for vector indexing, so that developers can observe the asynchronous write path in debug logs without changing the function's return type or behaviour. Auto-committed-on: macbook Co-authored-by: Medulla <medulla@tinyhumans.ai>
The store operation now explicitly drops the vectors handle after writing, allowing the vectors to complete asynchronously without blocking the caller. This avoids unnecessary waiting while ensuring the vectors still land after the store returns. Auto-committed-on: macbook Co-authored-by: Medulla <medulla@tinyhumans.ai>
Tiny Sweeper review
|
|
Warning Review limit reached
This review includes 6 billable files and costs up to $1.50. Or wait 48 minutes for your next included review. View limit detailsLimit details: You’ve used the included review currently available. Review configuration: ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (6)
Comment |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Memory::storecommitted a document only after its chunks had been embedded, so every write waited out one embedding round trip. An embedding failure does not fail the write, so a refused or timed-out provider cost its whole latency for nothing.OpenHuman autosaves the user message and the assistant message after every agent turn, as two sequential
storecalls, and the turn does not return until both are done. With a provider that refuses (an expired or placeholder key), a traced turn spent 655 ms + 847 ms = 1.5 s there, on the end of every task, and the same two calls cost a round trip each when the provider works.Change
UnifiedMemory::store_with_taint(theMemory::storepath) now commits the row and its chunks vector-less and returns. A background task embeds the chunks and attaches the vectors afterwards.documents_deferred.rsholds the path (documents.rsis already over 1000 lines). It reuseswrite_document_presanitized, andembed_chunk_textsnow delegates to an embedder-taking helper so the task needs no borrow of the store.write_gate::upsert_document_deferred).UPDATEper chunk: it matches the chunk id and its text, and only whereembedding IS NULL. A rewrite or forget while the embedding is in flight replaces or removes the chunks, so a stale vector finds nothing to attach to.Not changed:
upsert_document,upsert_documents(the connector batch path, which wants vectors present when it returns) andput_doc.Tests
documents_deferred_tests.rs, driven by an embedder whose requests wait on a semaphore:Memory::storedoes not wait on the provider (it would hang on the old code).cargo test --workspace,cargo clippy --all-targets --all-features -- -D warningsandcargo fmt --checkare clean locally.Follow-up
OpenHuman needs a gitlink bump to pick this up. Separately, the bench harness still runs with a placeholder TinyHumans key, which is what makes those embedding calls fail; that is tracked on the OpenHuman side.