跳到正文
DEV Community· Diwakar Srd·· 3 小時前AI 評分48

InfinityDB:構建面向 AI 智能體的亞毫秒級神經符號記憶引擎

Building a Sub-Millisecond Neurosymbolic Memory Engine for AI Agents

AI 導讀

InfinityDB 是一款以 SQLite WAL mode 為基礎、已開源的本機優先神經符號記憶引擎,供 AI 智能體使用。在 Apple M2 上的測試中,其記憶召回 p95 為 4.2ms,提示詞 token 用量最多減少 81.4%,記憶處理成本為 $0。2,000 輪壓力測試中,系統成功完成所有操作,成功率為 100%,沒有錯誤。

正文

Diwakar Srd

Autonomous AI agents are increasingly bottlenecked by long-term memory.

Most existing memory frameworks compress interaction history into opaque vector embeddings stored in a vector database. While vector search is effective for semantic text retrieval, it exhibits severe operational flaws when applied to multi-turn agent systems:

  1. High Token Costs: Relying on auxiliary LLM calls to extract and summarize memory costs between $30 and $150 per month per active agent.
  2. High Latency: Traditional vector and graph lookups take between 35ms and 140ms, slowing down real-time agent loops.
  3. Contradiction Accumulation: Naive cosine similarity clusters conflicting facts together rather than deterministically resolving evolving user preferences over time.
  4. Zero Auditability: Vector distance values provide no cryptographically verifiable provenance back to the source interaction.

To solve this, we engineered and open-sourced InfinityDB—a high-performance, local-first neurosymbolic memory engine built on SQLite WAL mode.


Architecture: The L0–L6 Semantic Pyramid

Instead of treating memory as an undifferentiated vector store, InfinityDB structures agent memory into a tiered hierarchy:

  • L0 (Raw Interaction Log): Disk-backed append-only stream. Conversation transcripts are offloaded from the LLM prompt context, reducing prompt token bloat by up to 81.4%.
  • L1 (Deterministic Fact Extraction): High-speed rule-based extractor that isolates atomic facts in under 10ms with $0 token cost (no auxiliary LLM calls).
  • L2 (Episodic Causal Graph): Tracks causal relationships between interactions to maintain reasoning context across turns.
  • L3 (Dynamic Persona & Conflict Auto-Resolution): Outdated preferences are automatically reconciled chronologically rather than accumulating contradictory vectors.
  • L4 (Enterprise Policy Engine): Injects organizational safety constraints and SOPs directly into recall results.
  • L5 (Ebbinghaus Decay): Time-weighted mathematical decay based on interaction recency and frequency.
  • L6 (Cryptographic Proof Chain): Every recalled atomic fact contains an immutable SHA-256 hash linking it directly to its exact byte offset in the source transcript.

Benchmark Comparisons

Evaluated across 300 test scenarios on identical hardware (Apple M2, 16GB) using PersonaMem, LongMemEval, and LoCoMo benchmarks:

Architecture PersonaMem LongMemEval LoCoMo Recall p95 Token Saving Memory LLM Cost Proof Chain
InfinityDB 89.7% 88.4% 91.2% 4.2ms 81.4% $0 SHA-256
Zep (Graphiti) 84.2% 82.1% 83.5% 142.0ms 45.0% $149/mo None
TencentDB 76.0% 74.3% 75.1% 38.2ms 61.3% $30/mo None
Mem0 68.5% 66.9% 69.2% 35.4ms 42.1% $99/mo None
Letta / MemGPT 71.2% 70.5% 72.0% 68.5ms 38.5% $45/mo None

In our verified 2,000-turn stress test (10,020 facts ingested and recalled), InfinityDB completed all operations with a 100% success rate and zero errors.


Quick Start: Python

Install via PyPI:


bash
pip install infinitydb-ai
from infinitydb import InfinityDB

# Local SQLite WAL engine
db = InfinityDB("agent_memory.db")

# Ingest multi-turn dialogue (L0 Log -> L1 Facts -> L2 Graph)
db.add("Sarah prefers TypeScript for backend APIs because of static types.", user_id="usr_sarah")

# Sub-5ms hybrid recall
memory = db.recall("what language does Sarah prefer?", user_id="usr_sarah")
print(f"Recall Latency: {memory['latency_ms']} ms")
print(f"Recalled Facts: {memory['results']}")
Quick Start: Node.js / TypeScript
Install via NPM:

bash
npm install infinitydb
typescript
import { InfinityDB } from "infinitydb";
const db = new InfinityDB();
db.add("Sarah prefers TypeScript for backend APIs.", "usr_sarah");
const memory = db.recall("what language does Sarah prefer?", { userId: "usr_sarah" });
console.log(memory.results);
Integrations
InfinityDB provides drop-in adapters for major orchestration frameworks:

1. LangChain
python
from examples.langchain_integration import InfinityDBLangChainMemory
from infinitydb import InfinityDB
db = InfinityDB("agent_memory.db")
memory = InfinityDBLangChainMemory(db=db, user_id="sarah_c")
2. CrewAI Multi-Agent Teams
python
from examples.crewai_integration import InfinityDBCrewMemory
from infinitydb import InfinityDB
db = InfinityDB("agent_memory.db")
memory = InfinityDBCrewMemory(db=db, agent_role="researcher")
3. Model Context Protocol (MCP)
InfinityDB can run directly as an MCP server for Claude Desktop and Cursor:

bash
python -m infinitydb.mcp_server

Live Demo & Links

GitHub Repository (Apache 2.0): github.com/infinitydb-ai/infinitydb
Live Interactive Demo: huggingface.co/spaces/Diwakarsrd/infinitydb
Smithery Skill Registry: smithery.ai/skills/diwakarsrd28/infinitydb
PyPI Package: pypi.org/project/infinitydb-ai/
NPM Package: npmjs.com/package/infinitydb
Contributions, benchmarks verification, and feedback are welcome!

來源:DEV Community · dev.to