Skip to content

MaanasTaneja/inmemorykb

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 

Repository files navigation

🧠 inmemorykb

A lightweight, in-memory vector knowledge base built with SQLite + FAISS, designed for agent memory and fast prototyping.

Why?

During my internship at Cisco, I couldn’t use external vector DBs like Chroma due to internal Python/infra constraints. Our use case didn’t require a massive knowledge store — we just needed to persist small playbooks, internal factoids, and customer support logic for our agents.

So I built this: a simple, embeddable, one-file solution for agent memory.

  • No infra dependencies
  • Fast and cheap to use
  • Plug-and-play with LangChain-style LLMs
  • Works great with OpenAI or any embedding model
  • Supports chunking, categorization, summarization, and relevance filtering

🏗️ Architecture

  • SQLite (in-memory or file): Stores raw documents + metadata
  • FAISS: Handles vector similarity search
  • LangChain Embedding/LLM API: Powers embeddings and optionally structured summaries + relevance checks
  • Supports: Category-based retrieval, semantic chunking, document summarization, and relevancy filtering using LLMs

Example Use Case

Imagine you're building a customer support agent that needs to:

  • Access escalation procedures
  • Reference product playbooks
  • Retrieve best practices

Just load in your PDFs or markdown files, and this system chunks, embeds, and lets your agent retrieve with low-latency and minimal setup.


Features

  • In-memory SQLite storage (no setup required) (can provide backing file to store db on disk, additionally this is using SQLAlchemy so replace URL with postgres instance? That should work as well.)
  • FAISS-backed dense vector search
  • Per-category document organization
  • Embedding-based chunking (semantic or fixed)
  • Can enable each document to be summarized post retrieval (extract relevant signal from noise)
  • Allow LLM to discard documents that are not relevant to query during retrieval.
  • Easy-to-configure via KnowledgeBaseConfig

🔧 Usage

from langchain_openai import OpenAIEmbeddings, ChatOpenAI
from inmemorykb import IMVectordb, IMKnowledgeBase, KnowledgeBaseConfig

embeddings = OpenAIEmbeddings()
lm = ChatOpenAI(model="gpt-4")

vectordb = IMVectordb(embedding_model=embeddings)
kb = IMKnowledgeBase(vectordb, lm, config=KnowledgeBaseConfig(summarize=True, relevancy_check=True))

kb.add(
    doc_name="product_guide",
    doc_path="path/to/guide.pdf",
    category="support",
    use_semantic_chunking=True
)

response = kb.retrieve_category("how to escalate an issue?", category="support")
print(response)

About

In Memory Knowledge Base for Agents

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages