sarthak-chaturvedi / portfolio

MemoGrafter - Long-Term Memory for Chatbots 🧠

MemoGrafter is a server-side TypeScript library that gives chatbots long-term, topic-aware memory without replaying the full conversation history into every prompt.

It turns conversations into structured memory nodes, links related topics in a graph, and injects only the most relevant memory when the chatbot needs context.


📌 Project Snapshot

AreaDetails
TypeTypeScript / Node.js library
FocusChatbot memory, graph retrieval, memory grafting
StoragePostgreSQL + pgvector
ProvidersOpenAI, Anthropic, Gemini, custom adapters
GitHubmayhemking007/memo-grafter
NPMhttps://www.npmjs.com/package/memo-grafter

💡 Why It Matters

Most chatbots forget anything outside the current context window. MemoGrafter solves this by converting long conversations into compact, searchable topic memory.

Its key idea is memory grafting: one chatbot or session can selectively absorb useful memory from another without copying the entire history.


🧩 Architecture

                         +----------------------+
                         |     Chatbot App      |
                         |  invoke(user input)  |
                         +----------+-----------+
                                    |
                                    v
                         +----------------------+
                         |  MemoGrafterAgent    |
                         |  memory-aware chat   |
                         +----------+-----------+
                                    |
                 +------------------+------------------+
                 |                                     |
                 v                                     v
        +------------------+                  +------------------+
        | Ingest Pipeline  |                  | Grafter Pipeline |
        | build memory     |                  | retrieve memory  |
        +--------+---------+                  +--------+---------+
                 |                                     |
                 v                                     v
        +------------------+                  +------------------+
        | Topic Detection  |                  | Relevant Nodes   |
        | Segmentation     |                  | Graph Neighbours |
        | Summarization    |                  | Token Budgeting  |
        +--------+---------+                  +--------+---------+
                 |                                     |
                 +------------------+------------------+
                                    |
                                    v
                         +----------------------+
                         | PostgresGraphStore   |
                         | messages, nodes,     |
                         | embeddings, edges    |
                         +----------+-----------+
                                    |
                                    v
                         +----------------------+
                         | PostgreSQL + pgvector|
                         +----------------------+

External adapters:
  - LLM adapter: summarizes segments and generates chatbot responses
  - Embedding adapter: converts messages and memory nodes into vectors

🧱 Core Components

ComponentRole
MemoGrafterLow-level memory core.
MemoGrafterAgentChatbot wrapper with invoke(), ingestion, and grafting.
IngestPipelineConverts conversations into topic memory.
TopicDriftDetectorDetects topic changes and reentry.
GrafterPipelineBuilds memory prompts from retrieved nodes.
PostgresGraphStoreStores messages, embeddings, nodes, and graph edges.
MemoGrafterFleetEnables memory sharing across multiple chatbots.

🔄 Application Flow

  1. A chatbot receives messages through MemoGrafterAgent.invoke().
  2. Messages are stored and embedded.
  3. Topic drift detection groups messages into segments.
  4. Segments become summarized memory nodes.
  5. Related nodes are connected in a graph.
  6. Relevant nodes are retrieved when memory is needed.
  7. MemoGrafter builds a token-budget-aware memory prompt.
  8. Another chatbot can graft selected memory into its own graph.

⚙️ Key Features

  • Topic-based long-term memory
  • Relevant memory injection without full-history replay
  • Memory grafting between chatbots or sessions
  • PostgreSQL + pgvector graph storage
  • Provider adapters for OpenAI, Anthropic, Gemini, and custom models
  • Optional BullMQ + Redis background ingestion
  • Fleet API for multi-chatbot memory sharing

✅ Summary

MemoGrafter is my flagship AI infrastructure project. It shows my ability to design reusable backend systems for LLM applications, especially around memory, retrieval, embeddings, graph storage, and prompt construction.