Repository navigation
feat: add opt-in evidence-backed knowledge memory - #183
Draft
00-Aakash-00 wants to merge 3 commits into
Draft
00-Aakash-00 wants to merge 3 commits into
00-Aakash-00 wants to merge 3 commits into
Conversation
This branch has not been deployed
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.
OpenInstinct’s existing profile memory is a small model-maintained document. This adds experimental knowledge memory with source evidence, revision history, immediate corrections and forgetting, background extraction, and an inspection page. A preference remembered in one chat can be corrected in another and retrieved with evidence; forgetting removes the saved versions and fences delayed jobs from restoring them.
The feature is off by default, with
off,shadow, andenabledmodes plus a workspace allowlist. It reuses the existing Eve, Drizzle/PostgreSQL, AI SDK, Zod, private Vercel Blob, tRPC, and UI primitives. No new dependencies or lockfile changes. Repository patterns and AGENTS.md were followed; no separate CONTRIBUTING guide or PR template was present.Implementation
/memorysupports inspection, search, evidence/history, correction, forgetting and JSON/Markdown export. Requests derive scope from an authenticated owned chat.memory.statusexposes scoped queue counts/timestamps and workspace-wide daily usage without saved text.Usage budgets
KNOWLEDGE_MEMORY_DAILY_TOKENS=250000andKNOWLEDGE_MEMORY_DAILY_CALLS=100apply per workspace across memory scopes, using the UTC call-start day. Atomic reservations precede every extraction, including retries. Reported usage settles once; unknown/partial usage and abandoned calls retain conservative charges. The ledger records model metadata, attempts and accepted-proposal counts, including retry and empty-proposal costs, without storing prompts or output.Exhaustion defers extraction without consuming retries. Either limit at zero pauses extraction and preserves queued input. Requests larger than an entire positive allowance fail without a model call and cannot starve later input. Explicit edits, export publication, forgetting and purge continue independently of extraction budgets. Regression coverage includes explicit saves racing budget rejection/deferral.
Reservations use serialized prompt/schema bytes plus output and framing allowances. They are not exact tokenizer counts or a dollar cap. Reported overruns are charged and prevent later admission. Non-content usage metadata survives record forgetting and is deleted with its workspace.
Validation
pnpm check --concurrency=1: all six tasks passed, including 1,134 tests across 112 files, TypeScript, lint, formatting and unused-code checks. No test timeouts or assertions were relaxed.pnpm build: passed with memory enabled and synthetic local configuration.pnpm db:checkand all 17 migrations into fresh PostgreSQL 17: passed.pnpm test:runtime: 3 evaluations / 17 gates passed, proving memory binding and timestamped receipts precede first-turn tool execution.The deterministic suites include the full remember → correct → recall → forget flow across fresh provider contexts, ownership, replay/compaction, revision conflicts, stale workers, source recovery, upload failure, account deletion and migration races. Earlier independent browser QA passed 39 tested branches after fixing five UI issues; this follow-up does not change that UI.
Executable benchmarks:
pnpm bench:memory:scenarios: 40 frozen scenarios × 3 repetitions = 120 passing evidence gates against real services/migrations in PGlite. Model extraction, Blob and recovery HTTP use fixtures. The JSON report separates unsupported legacy APIs, shared behavior not run against the baseline, and semantic quality not measured.pnpm bench:memory:scale: three independent 1,000-record runs, 30 warm samples per operation per run. Older-target search p95 10.315–10.602 ms; full fresh recall p95 27.709–28.712 ms. Multilingual recall is 17,227 UTF-8 bytes, reduced from 24,560 bytes after the benchmark exposed the old character-based limit. Escaping/multilingual regression tests preserve whole lines and records.Local scale results measure PGlite/WASM, not hosted PostgreSQL, network latency, production queue freshness or model answer quality. Byte bounds do not establish the proposed 4,500-token recall target.
Rollout limits
This remains a draft pending live model and deployed private Blob validation. Two opt-in live flows now cover explicit controls and ordinary input → scheduled maintenance → fresh recall, each repeated three times. They are implemented but not executed here because AI Gateway/OIDC and target storage credentials are unavailable. Runtime smoke uses the existing deterministic model fixture. The live-eval supervisor cleans synthetic artifacts before deleting its disposable database, retaining cleanup state if deletion fails.
Upstream Checks and Vercel preview deployment require maintainer authorization for this contributor PR. Passing local validation is not a completed upstream CI or preview deployment.
The extractor is conservative: English first-person statements, exact quotes and supported co-mentions. It does not infer personality, merge entities, interpret relative dates, ingest arbitrary browser content or mirror personal data into Git. Richer entities, knowledge-to-workstream links and synthesized active context remain separate follow-ups. The 40 deterministic cases and two live flows do not claim completion of the broader 40-scenario live semantic comparison.
Authorization/input-request events stop capture for that chat while preserving earlier independent memories. Exhausted or permanently oversized inputs discard unsupported text while retaining non-content replay fences. Forgotten saved content is unavailable immediately; physical artifact purge is retryable. Original conversations, downloaded exports and provider backups are outside saved-memory deletion. See configuration, migration, benchmark and operational details.
Inspiration
Inspired by Dhravya Shah’s article about Instinct’s memory. The article is an outside-in reconstruction of a closed product. This is an independent implementation for OpenInstinct, with no claim to reproduce Instinct’s source or measured behavior.