HNSW & Token Tuning
Controlling Memory Deduplication & Consolidation LLM Budgets
Avoid runaway extraction costs by pre-filtering redundant facts with cosine similarity gates and routing ADD/UPDATE/DELETE prompts to Xiaomi MiMo.
Cosine Gate >= 0.88 · Batch 2 Turns · 85%+ Cheaper via MiMo
Hidden Costs Inside Synchronous add() Calls
Every naive add() call invokes an extraction prompt plus an update-resolution prompt comparing new facts against existing memories. On busy 10,000-session/day apps, running this on frontier models costs hundreds of dollars daily.
Short-Circuiting No-Op Turns
Run a lightweight regex and token-length filter in your Celery worker before calling the extractor LLM: messages under 6 tokens without entity nouns rarely produce durable long-term facts.
Measured Thresholds & Vector Stack Parameters
| Optimization Lever | LLM Call Reduction | Implementation Detail |
|---|---|---|
| Batch 2-3 Turns per Extract | -45% to -60% API calls | Skip trivial acknowledgments ("ok", "thanks") |
| Top-3 Candidate Context Only | -55% prompt tokens/add | Pass only top 3 cosine neighbors into UPDATE judge |
| Xiaomi MiMo Extraction Tier | -95% $/1M token rate | $0.10/1M input vs $2.50-$3.00/1M frontier |