Repository navigation
feat(transfer): export/import documents between banks without re-running the LLM - #1909
Merged
Merged
Conversation
nicoloboschi
force-pushed
the
feat/document-transfer
branch
12 times, most recently
from
June 3, 2026 10:38
c4a8b53 to
ebd594a
Compare
…ing the LLM
Export a bank's already-extracted facts (text, entity canonical names, causal
links, chunks) to a ZIP archive, and import them into another bank by replaying
the deterministic half of the retain pipeline — re-embedding locally with the
target bank's model and re-resolving entities. No LLM fact extraction runs on
import. Consolidated observations are excluded (regenerated by consolidation in
the target bank).
Two use cases: testing a different embedding model, and moving data between
banks/instances without LLM cost.
- engine/transfer/: schema, export, importer (LLM-free replay)
- MemoryEngine.export_documents_async / import_documents_async
- Admin CLI: export-documents / import-documents
- HTTP API: GET/POST /v1/default/banks/{bank_id}/document-transfer
- Gated by HINDSIGHT_API_ENABLE_DOCUMENT_EXPORT_API / _IMPORT_API
(default on), surfaced via /version features for the control plane
- Control plane Documents page: Export All / Import (zip upload) +
per-document Export, hidden when the backend disables the feature
- Tests, docs, regenerated OpenAPI spec and client SDKs
… import Imported documents were second-class citizens: unlike a normal retain, an import fired no retain.completed webhooks and never enqueued consolidation or graph maintenance, so imported facts never produced observations. Thread an outbox callback factory through import_documents -> _import_one_document so each imported document fires its retain.completed webhook transactionally inside its own insert. After the import completes, submit async consolidation (when observations + auto-consolidation are enabled) and graph maintenance, mirroring the post-retain side effects.
…in and import The consolidation + graph-maintenance triggers added for import duplicated the retain post-processing block verbatim. Extract it into _submit_post_insert_maintenance and call it from both the retain pipeline and the import pipeline, so the two paths stay in lockstep.
Import now fires the post-retain extension hook (usage tracking / metrics / notifications) once per imported document, mirroring retain — so imported facts are first-class for extensions. Token counts are zero and processed_content_tokens is 0 (import runs no LLM extraction), so cost-metering extensions correctly bill an import as free. The importer returns per-document outcomes (ImportedDocument) so the engine can build the RetainResult; these are not serialized into the operation's result_metadata (the worker still writes counts only). Tests: assert the hook fires once per document with zero tokens, and that import queues a retain.completed webhook delivery per document.
nicoloboschi
force-pushed
the
feat/document-transfer
branch
from
June 3, 2026 14:04
51452be to
bbbac16
Compare
cdbartholomew
added a commit
that referenced
this pull request
Oct 20, 2026
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.
What
Adds a document transfer feature: export a bank's already-extracted facts to a ZIP archive and import them into another bank (or instance) without re-running the LLM.
Since fact extraction is the expensive, non-deterministic part of ingestion, transferring already-extracted facts is fast, cheap, and reproducible.
Two target use cases:
How it works
world/experiencefacts (text, timestamps, context, tags, metadata, observation scopes), each fact's entities by canonical name, and causal links (as ordinals). No embeddings, no DB ids.on_conflict:skip(default) /replace/new-idfor existing document ids.Surfaces
hindsight_api/engine/transfer/(schema, export, importer) +MemoryEngine.export_documents_async/import_documents_async.hindsight-admin export-documents/import-documents.GET/POST /v1/default/banks/{bank_id}/document-transfer(export streams a zip; import is a multipart upload).HINDSIGHT_API_ENABLE_DOCUMENT_EXPORT_APIHINDSIGHT_API_ENABLE_DOCUMENT_IMPORT_API/versionfeatures.document_export_api/document_import_api.Tests
tests/test_document_transfer.py:on_conflictmodes (skip / replace / new-id)./versionreports disabled when flags are off.on_conflict.Docs / generated
developer/document-transfer.md(+ sidebar), admin-cli and configuration references updated.🤖 Generated with Claude Code