A standalone, framework-agnostic semantic memory engine and TypeScript SDK for intelligent ingestion, hybrid retrieval, and forgetting-curve resurfacing.
Humans remember ideas, metaphors, and analogies — not filenames or exact keywords.
You don't remember saving video_98412_transcript.txt. You remember "there was a video where the guy compared salary negotiation to buying real estate."
Every "save for later" feature turns into a digital graveyard because:
- Storage is trivial; retrieval is broken. Databases index exact keywords, while human recall operates on fuzzy conceptual associations.
- Infinite archives cause fatigue. Unreviewed saved items decay in human memory unless intelligently resurfaced at the optimal moment.
MemoryEngine is pure infrastructure designed to solve this. It has no UI — it is an importable, high-performance SDK that turns raw text from any source (Instagram reels, podcasts, PDFs, voice notes, bookmarks) into queryable, connected, and serendipitously resurfaced memories.
npm install @paritosh31/memory-engineimport { MemoryEngine } from "@paritosh31/memory-engine";
const engine = new MemoryEngine();
// 1. Ingest any text
await engine.ingest({
id: "reel_1042",
title: "Salary Negotiation Tactics",
text: "When negotiating salary, never make it adversarial. Think of it like buying a house where both parties need peace of mind."
});
// 2. Semantic Search by conceptual analogy
const results = await engine.search("salary negotiation real estate analogy");
console.log(results.hits[0].bestChunk.text);
// 3. Resurface forgotten memories via Ebbinghaus decay
const digest = await engine.resurface({ decayThreshold: 0.4 }); ┌────────────────────────────────────────────────────────┐
│ Application Layer │
│ (Vault / SaaS App / Worker / CLI) │
└──────────────────────────┬─────────────────────────────┘
│
MemoryEngine SDK
│
┌──────────────────┬───────────────────────┼─────────────────────────┬──────────────────┐
│ │ │ │ │
▼ ▼ ▼ ▼ ▼
┌──────────────┐ ┌──────────────┐ ┌────────────────┐ ┌──────────────┐ ┌──────────────┐
│ Ingestion │ │ Embeddings │ │ Storage Engine │ │ Retrieval │ │ Resurfacing │
├──────────────┤ ├──────────────┤ ├────────────────┤ ├──────────────┤ ├──────────────┤
│ • Normalizer │ │ • OpenAI │ │ • PgVector │ │ • Dense HNSW │ │ • Ebbinghaus │
│ • Semantic │ │ • Gemini │ ──► │ • In-Memory │ ◄────── │ • Sparse BM25│ │ Decay │
│ Chunker │ │ • Local/Mock │ │ • DDL Schema │ │ • RRF Fusion │ │ • Graph Link │
│ • Extractor │ │ • Extensible │ │ Migrations │ │ • Reranking │ │ • Serendipity│
└──────────────┘ └──────────────┘ └────────────────┘ └──────────────┘ └──────────────┘
Combines dense semantic vector search (HNSW cosine similarity) with sparse lexical search (BM25) to deliver both semantic understanding and exact keyword precision:
Calculates memory retention probability based on elapsed time and active recall reinforcements:
Memories that have decayed below your retention threshold (
Discovers conceptual links across disparate sources (e.g., connecting a psychology note from 6 months ago to an engineering video saved today) through high-dimensional cosine affinity.
import { MemoryEngine, PgVectorStorage, OpenAIEmbedder } from "memory-engine";
const engine = new MemoryEngine({
// Storage Adapter: In-Memory (default) or PostgreSQL + pgvector
storage: new PgVectorStorage({
connectionString: process.env.DATABASE_URL
}),
// Embedding Provider: Mock (default), OpenAI, or Gemini
embedding: new OpenAIEmbedder({
apiKey: process.env.OPENAI_API_KEY,
model: "text-embedding-3-small"
}),
// Chunker Configuration
chunking: {
maxChunkSizeChars: 1200,
chunkOverlapChars: 150
}
});Run the built-in benchmark harness:
npm run benchmark| Metric | In-Memory Store | PostgreSQL + pgvector (HNSW) |
|---|---|---|
| Ingestion Throughput | ~2,400 docs/sec | ~480 docs/sec |
| Dense Search Latency (p50) | 0.42 ms | 4.8 ms |
| Sparse BM25 Latency (p50) | 0.28 ms | 3.2 ms |
| Hybrid RRF Latency (p50) | 0.75 ms | 6.1 ms |
| Conceptual Recall Accuracy | 100% | 100% |
- Step-by-Step Integration & Setup Guide
- Architecture Deep Dive
- Benchmark Results
- Technical Essay: Why Saved Collections Become Graveyards
MIT © Paritosh Srivastava