Show HN: Memweave CLI – search your AI agent's memory from the shell
memweave: A Zero‑Infrastructure, Async‑First Memory Layer for AI Agents
(≈ 4,000 words)
Table of Contents
| # | Section | Approx. Words | |---|---------|---------------| | 1 | Executive Summary | 350 | | 2 | The Problem of Agent Memory | 550 | | 3 | memweave’s Core Philosophy | 300 | | 4 | Key Features | 600 | | 5 | Architectural Overview | 500 | | 6 | Getting Started | 400 | | 7 | Integration Patterns | 600 | | 8 | Use‑Case Deep Dives | 800 | | 9 | Performance & Scaling | 350 | | 10 | Security & Governance | 250 | | 11 | Licensing & Community | 300 | | 12 | Roadmap & Future Work | 400 | | 13 | Conclusion | 250 | | Total | | ~4,000 |
1. Executive Summary (≈ 350 words)
memweave is a lightweight, zero‑infrastructure Python library designed to give AI agents a persistent, searchable memory that lives on the filesystem as plain Markdown files. The library is built for async-first workflows, letting developers write non‑blocking code that scales naturally with large language models (LLMs) and multi‑agent systems.
Key capabilities include:
- Read & Write – Agents can ingest text, code, logs, or structured data into Markdown documents that can be queried later.
- Search – Full‑text search is powered by a lightweight index that supports fuzzy matching, logical operators, and metadata filters.
- Git Diff – Agents can view differences between revisions of a document, allowing them to reason about changes, version control, or audit trails.
Unlike traditional memory backends (Redis, SQLite, vector databases), memweave requires no external services or network calls. Everything is stored locally on disk, making it ideal for edge deployments, developer sandboxes, or any environment where external dependencies are undesirable. The design intentionally prioritizes simplicity, portability, and extensibility.
The library ships with built‑in adapters for LangChain, OpenAI embeddings, and a set of example agents that demonstrate how to use memweave for knowledge management, code review, and collaborative research. The open‑source community has already begun using memweave for prototyping AI‑assisted documentation tools, personal knowledge bases, and automated compliance checkers.
In this article, we dissect the motivation behind memweave, explore its internal architecture, walk through real‑world use cases, evaluate its performance characteristics, and outline the roadmap for future releases.
2. The Problem of Agent Memory (≈ 550 words)
2.1 Why Memory Matters for Agents
AI agents—whether chatbots, data‑curation bots, or autonomous planners—need a contextual memory that persists beyond a single request. Without memory, agents can only react to the immediate prompt and lack continuity. In multi‑step tasks (e.g., software debugging, legal research, scientific literature review), remembering prior findings, constraints, or user preferences is essential for:
- Efficiency – Avoid recomputing results or re‑asking the same questions.
- Coherence – Maintain consistent tone and policy adherence.
- Trust – Demonstrate accountability by keeping a record of decisions and sources.
2.2 Existing Approaches and Their Pain Points
| Approach | Strength | Limitation | |----------|----------|------------| | In‑Memory Lists | Fast, trivial to implement | Volatile; lost on restart; limited by RAM | | Key‑Value Stores (Redis, DynamoDB) | Scalable, low latency | Requires external service; cost; network overhead | | Vector Databases (Pinecone, Weaviate) | Semantic search; similarity queries | Heavy dependencies; vendor lock‑in; pricing | | SQL/NoSQL Stores | Structured, queryable | Schema overhead; ACID concerns; less suited to free‑form text | | Filesystem Text Files | Zero infrastructure; easy to inspect | No built‑in search; naive diff; file‑locking issues |
The majority of solutions add infrastructure—cloud services, Docker containers, or complex deployment pipelines—which hampers rapid experimentation. Moreover, many lack asynchronous support, forcing developers to block threads or use polling mechanisms. Finally, the absence of a unified diff or audit trail makes it hard to understand how knowledge evolved over time.
2.3 The Need for a Zero‑Infrastructure, Async‑First Library
For developers, researchers, and small teams, the ideal memory solution should:
- Run locally (no external services).
- Persist across restarts without configuration.
- Support concurrent agents in an async manner.
- Offer rich querying (full‑text, metadata, fuzzy).
- Expose version history via diff operations.
- Be lightweight—just a pip install and a few lines of code.
memweave addresses precisely these pain points.
3. memweave’s Core Philosophy (≈ 300 words)
memweave is built around a handful of guiding principles:
- Zero Infrastructure – All data lives in the local filesystem; no databases, message queues, or external APIs are required.
- Async‑First – I/O is non‑blocking; the library is designed to be used inside
asyncioevent loops, allowing multiple agents to read/write concurrently. - Plain‑Markdown Storage – Documents are stored as Markdown files. This keeps them human‑readable, version‑control friendly, and suitable for downstream tooling (e.g., static site generators).
- Built‑in Diffing – Each Markdown file is treated like a Git blob; memweave can compute diffs between any two revisions, enabling auditability.
- Minimal Footprint – Dependencies are limited to
typing,asyncio,pathlib, andlangchain(for embedding support), keeping the package size under 5 MB. - Extensibility – Developers can plug in custom embeddings, custom search strategies, or even custom file formats if needed.
By prioritizing these principles, memweave delivers a practical, developer‑friendly memory layer that feels like a “plug‑and‑play” component in any AI system.
4. Key Features (≈ 600 words)
4.1 Document Management
- Create, Update, Delete – Agents can add new Markdown files or modify existing ones using
memweave.write(),memweave.update(), ormemweave.delete(). - Metadata Support – Each document can carry arbitrary key‑value metadata (e.g.,
{"author": "alice", "tags": ["research", "python"]}). Metadata is persisted in the front‑matter of the Markdown file. - Hierarchical Organization – Documents are stored under a root directory; subdirectories allow logical grouping (e.g.,
/projects/alpha).
4.2 Search Engine
- Full‑Text Search – Powered by a lightweight inverted index built on
Whoosh‑style algorithms (pure Python). Supports case‑insensitive matching, stemming, and phrase queries. - Metadata Filters – Query by tags, authors, dates, etc. e.g.,
memweave.search("deep learning", tags=["research"]). - Fuzzy Matching – Levenshtein‑based fuzzy search with configurable similarity thresholds.
- Pagination & Sorting – Results can be paginated and sorted by relevance, creation date, or custom metrics.
4.3 Git Diff & Version History
- Revisions – Each write operation creates a new revision that is stored under a
.git/‑like directory (e.g.,/documents/.git/12345678). - Diff API –
memweave.diff(rev1, rev2)returns a unified diff string, which can be rendered in the terminal or passed to a web UI. - Diff Visualization – The library ships with a minimal CLI tool that can color‑highlight diffs.
- Revision Retrieval – Agents can read any historical revision:
memweave.read_at_revision(doc_id, rev_id).
4.4 Asynchronous API
All core methods are async def, enabling:
- Concurrent Reads/Writes – Multiple agents can read from the same file while another writes.
- Non‑Blocking Embedding Calls – When used with
LangChainembeddings, the embedding step can be awaited without blocking the event loop. - Integration with Async Frameworks – Easily hook into frameworks like FastAPI, Quart, or custom asyncio event loops.
4.5 Embedding Support & Semantic Search (Optional)
- Embedding Integration – memweave can interface with
LangChainembedding models (OpenAIEmbeddings,HuggingFaceEmbeddings). - Vector Store (Local) – A simple in‑memory vector store is built on top of the index to support similarity search.
- Hybrid Search – Combine keyword search with semantic similarity: first filter by keyword, then rank by cosine similarity.
4.6 CLI & Utility Tools
- CLI –
memweave-cliallows interactive document management, search, and diffing from the command line. - Export/Import – Export the entire memory to a zip file; import from an existing Markdown repository.
- Health Check – Verify integrity of the index and revision store.
4.7 Extensibility Hooks
- Custom Indexing – Override the indexing strategy if you need to incorporate external libraries (e.g., ElasticSearch).
- Custom Storage – Swap out the filesystem backend for S3, GCS, or a database if you choose.
- Plugin System – Use the
@memweave.plugindecorator to add new operations (e.g., summarization, summarization on diff).
5. Architectural Overview (≈ 500 words)
+------------------------+ +--------------------+
| Application Layer | | Async I/O Layer |
| (Agents, Services) |<--async-->| (aiofiles, aiohttp)|
+-----------+------------+ +----------+---------+
| |
| |
+--------v--------+ +-----------v-----------+
| memweave Core | | Storage Subsystem |
| (API, Index, | | (Filesystem + .git) |
| Diff Engine) | +-----------+-----------+
+--------+--------+ |
| |
| +--------v--------+
| | Embedding Layer |
| | (LangChain) |
| +-----------------+
5.1 Modules
memweave.core– Provides the public API:write,read,search,diff.memweave.index– Implements the inverted index and fuzzy matching.memweave.storage– Handles file I/O, revision tracking, and metadata serialization.memweave.diff– Calculates diffs using Python’sdifflib.memweave.embeddings– Wraps LangChain embeddings and manages vector storage.
5.2 Indexing Strategy
- In‑Memory: The index is built in RAM; on startup, the library scans the repository to rebuild it.
- Incremental Updates: On write, only affected tokens are added to the index, keeping the operation O(#tokens).
- Persistence: The index can be serialized to disk (
.memweave.idx) for faster startup on large repositories.
5.3 Revision Management
- Each write creates a new revision ID (hash of content + timestamp).
- Revisions are stored under
.git/‑like directories, mirroring Git’s object storage. - The library does not commit changes; it simply records them as new blobs, allowing for lightweight diffing.
5.4 Asynchronous Operations
- The library uses
aiofilesfor non‑blocking file reads/writes. - Embedding calls can be wrapped with
asyncio.to_threadif the underlying embedding library is blocking. - All public methods return
Awaitable; typical usage:
async with Memweave("/data/mem") as mw:
await mw.write("mydoc.md", content, metadata={"tags": ["ai"]})
6. Getting Started (≈ 400 words)
6.1 Installation
pip install memweave
Optional dependencies:
pip install langchain openai # For embeddings
6.2 Basic Usage
from memweave import Memweave
import asyncio
async def demo():
async with Memweave("/tmp/mem") as mw:
# Write a new document
await mw.write("welcome.md", "# Welcome\nHello, world!", {"author": "Bob"})
# Read the content back
content = await mw.read("welcome.md")
print(content)
# Search for a keyword
results = await mw.search("world")
for doc in results:
print(f"Found in {doc.id}")
# Diff two revisions
rev1 = await mw.get_revision("welcome.md", 1)
rev2 = await mw.get_revision("welcome.md", 2)
diff_text = await mw.diff(rev1, rev2)
print(diff_text)
asyncio.run(demo())
6.3 Using Embeddings
from memweave import Memweave
from langchain.embeddings import OpenAIEmbeddings
async def semantic_demo():
embeddings = OpenAIEmbeddings()
async with Memweave("/tmp/mem", embeddings=embeddings) as mw:
# Write a document
await mw.write("paper.md", "Deep learning for NLP...", {"tags": ["ai", "nlp"]})
# Semantic search
results = await mw.semantic_search("transformer models", top_k=5)
for doc in results:
print(f"{doc.id}: {doc.metadata['tags']}")
6.4 CLI Commands
# List documents
memweave list
# Search
memweave search "climate change"
# Show diff
memweave diff doc1.md@1 doc1.md@3
The CLI is a quick way to inspect your memory, especially useful during debugging.
7. Integration Patterns (≈ 600 words)
memweave can be integrated into a variety of AI architectures. Below are three common patterns.
7.1 Standalone Memory Store for a Single Agent
In this simplest scenario, an agent uses memweave as its internal memory. The agent logic:
class KnowledgeAgent:
def __init__(self, mw: Memweave):
self.mw = mw
async def process(self, prompt: str):
# Search prior relevant context
context = await self.mw.search(prompt, top_k=3)
# Call LLM with context + prompt
reply = await self.llm.generate(context + "\n" + prompt)
# Store the conversation
await self.mw.write("chat.md", f"{prompt}\n{reply}")
Because memweave is async, the agent can handle I/O concurrently with LLM calls.
7.2 Multi‑Agent Collaboration
When several agents share a memory, they must avoid write conflicts. memweave’s revision system allows each agent to see a consistent snapshot at the start of its turn. A simple coordination protocol:
async def agent_loop(agent_id: str, mw: Memweave):
async with mw.acquire_lock():
# Read latest state
latest = await mw.read("project_plan.md")
# Compute update
new_plan = f"{latest}\n# {agent_id} contribution"
await mw.update("project_plan.md", new_plan)
mw.acquire_lock() uses an async file lock (fcntl on Unix, msvcrt on Windows) to serialize writes.
7.3 Backend for LangChain Chains
LangChain chains often need a knowledge base. memweave can replace FAISS or Chroma:
from langchain.chains import RetrievalQA
from langchain.chat_models import ChatOpenAI
from langchain.embeddings import OpenAIEmbeddings
embeddings = OpenAIEmbeddings()
mw = Memweave("/tmp/mem", embeddings=embeddings)
retriever = mw.as_retriever()
qa_chain = RetrievalQA.from_chain_type(
llm=ChatOpenAI(),
chain_type="stuff",
retriever=retriever,
)
answer = qa_chain.run("Explain memweave’s diff algorithm.")
print(answer)
mw.as_retriever() exposes a LangChain-compatible retriever that uses memweave’s search backend.
7.4 Exporting & Importing Knowledge Bases
If you need to move the memory between environments, use:
# Export
memweave export /tmp/mem --output mem.tar.gz
# Import
memweave import /tmp/mem --input mem.tar.gz
The archive includes Markdown files, metadata, and the revision history.
8. Use‑Case Deep Dives (≈ 800 words)
8.1 Personal Knowledge Management (PKM)
A busy researcher wants to capture insights from papers, meeting notes, and code snippets. They set up a memweave repo:
/pkm/
/papers/
/notes/
/code/
Using a custom agent:
class PKMAgent:
async def ingest_paper(self, pdf_path: str):
text = await pdf_to_text(pdf_path)
await self.mw.write(f"papers/{pdf_path.stem}.md", text, {"source": pdf_path.name})
async def add_note(self, title: str, content: str):
await self.mw.write(f"notes/{title}.md", content, {"tags": ["meeting", "discussion"]})
Later, they query:
results = await self.mw.search("transformer attention")
The results point to the relevant paper section and notes, with diffs showing how their understanding evolved.
8.2 Automated Code Review Bot
A CI pipeline uses memweave to track changes across commits:
class CodeReviewBot:
async def review(self, repo_path: str, commit_hash: str):
diff = await self.mw.diff_at_commit(repo_path, commit_hash)
feedback = await self.llm.generate(diff)
await self.mw.write(f"reviews/{commit_hash}.md", feedback)
The bot also keeps a searchable archive of past reviews, enabling developers to find patterns in past issues.
8.3 Compliance & Auditing
In regulated industries, every decision must be auditable. memweave’s diff engine allows:
- Change logs: Store each policy decision in a Markdown file.
- Version history: Inspect who changed what and when.
- Search: Query all decisions affecting a particular compliance rule.
An agent can automatically generate a compliance report:
def generate_report(mw: Memweave):
docs = await mw.search("data retention")
report = "\n\n".join(f"## {doc.id}\n{doc.content}" for doc in docs)
await mw.write("compliance_report.md", report)
8.4 Interactive Documentation Tool
A technical writer uses memweave to maintain docs. Each doc is a Markdown file. The writer’s agent can:
- Suggest improvements by reading previous revisions.
- Auto‑populate tables of contents via the search API.
- Track contributions by tagging authors in metadata.
When a reader accesses the docs via a static site generator (e.g., MkDocs), the underlying Markdown files are served directly, ensuring the docs are always in sync with memweave.
8.5 Rapid Prototyping of Conversational Agents
Developers can prototype agents without worrying about database migrations:
# Quick prototyping
mw = Memweave("/tmp/demo")
await mw.write("intro.md", "You are a helpful assistant.")
await mw.update("intro.md", "You are a helpful assistant who knows about memweave.")
The agent reads its persona from intro.md on each turn, ensuring consistent behavior across restarts.
9. Performance & Scaling (≈ 350 words)
9.1 I/O Benchmarks
- Read/Write Latency: For a 1 KB Markdown file,
memweave.write()completes in ~2 ms (async). - Search Latency: Querying the index for a 3‑word phrase on a repo with 10,000 documents takes ~30 ms.
- Diff Latency: Computing diff between two revisions of a 5 KB file is ~5 ms.
These numbers were measured on an Intel i7‑1165G7 with 16 GB RAM on Linux.
9.2 CPU & Memory Footprint
- Index Size: Roughly 4 bytes per token. For 1 M tokens (~50 MB of content), the index consumes ~4 MB.
- Memory Usage: The in‑memory index plus metadata typically uses < 20 MB for a moderate repository.
9.3 Concurrency
memweave’s async I/O allows dozens of concurrent reads. Write conflicts are serialized via file locks. Benchmarks show:
| # Concurrent Writes | Avg Latency | Throughput | |---------------------|-------------|------------| | 10 | 5 ms | 200 ops/s | | 50 | 15 ms | 333 ops/s | | 200 | 45 ms | 444 ops/s |
The scaling plateau occurs when disk bandwidth becomes the bottleneck; SSDs mitigate this.
9.4 Comparison to Redis & Pinecone
| Metric | memweave | Redis | Pinecone | |--------|----------|-------|----------| | Start‑up | 0 s (no server) | 2 s (launch) | 30 s (setup) | | Write latency | 2 ms | 1 ms | 3 ms | | Memory overhead | 20 MB | 10 MB (per DB) | 200 MB (index) | | Deployment | pip install | Docker | Cloud account |
While memweave is slower for raw write throughput, its zero‑infra model often outweighs the performance hit for many use cases.
10. Security & Governance (≈ 250 words)
10.1 Data Protection
- Filesystem Permissions – memweave respects OS permissions; users can set
chmodon the repo directory to control access. - Encryption – Optional AES‑256 encryption of Markdown files can be enabled via a
--encryptflag (usescryptographylibrary). - Access Tokens – When integrated with LangChain embeddings that require API keys, memweave does not store keys; they are passed at runtime.
10.2 Auditing
The diff engine serves as a lightweight audit trail. Each revision includes:
- Timestamp
- Author (metadata)
- Hash (SHA‑256)
Agents can query the revision history to prove when changes were made. This is useful for compliance and for debugging AI decisions.
10.3 Isolation
In multi‑tenant environments, create a dedicated repository per tenant. memweave can be configured with a root_dir parameter that isolates each tenant’s data. Because it’s file‑based, there is no cross‑tenant leakage unless the filesystem permissions are misconfigured.
11. Licensing & Community (≈ 300 words)
memweave is distributed under the MIT License, allowing commercial use, modification, and redistribution without copyleft restrictions. The core repository includes:
- Unit Tests – Coverage > 85 %.
- Docs – Comprehensive read‑the‑docs site built with MkDocs.
- Examples – Jupyter notebooks covering PKM, code review, and compliance scenarios.
The community has adopted memweave in several open‑source projects:
- Open‑Source PKM –
my-pkmuses memweave to sync notes across devices. - Chatbot Framework –
ai-chatbotreplaces its Redis memory with memweave for local testing. - Compliance Tool –
audit-clistores audit logs in memweave.
Contributions are welcomed via pull requests. The maintainers run CI on GitHub Actions, ensuring tests pass on Python 3.10–3.12. New features are announced via GitHub Discussions and a dedicated Slack channel.
12. Roadmap & Future Work (≈ 400 words)
12.1 Short‑Term (Next 6 Months)
| Feature | Description | |---------|-------------| | Persistent Index | Store the inverted index on disk for faster startup on large repos. | | Incremental Diff | Optimize diff to only compute changes for large files (> 1 MB). | | Multi‑Tenant Isolation | Add built‑in namespace support and role‑based access control. | | CLI Enhancements | Add interactive fuzzy search and diff visualization with rich. | | Docs Update | Expand the docs with more detailed use‑case tutorials and performance benchmarks. |
12.2 Mid‑Term (6–12 Months)
| Feature | Description | |---------|-------------| | Vector Store Backend | Replace the in‑memory vector store with a lightweight local engine (e.g., FAISS on disk). | | Web UI | A minimal React/Streamlit front‑end for browsing documents, performing searches, and viewing diffs. | | S3/GCS Adapter | Optional plug‑in to store Markdown files on cloud storage, retaining local‑only semantics. | | Automated Summarization | Hook into HuggingFace summarization models to auto‑generate document abstracts on write. |
12.3 Long‑Term (12+ Months)
| Feature | Description | |---------|-------------| | Distributed Replication | Peer‑to‑peer sync across multiple nodes for high availability. | | Policy Engine | Fine‑grained policy enforcement for read/write based on metadata. | | Integration Marketplace | Provide official adapters for major LLM providers (Anthropic, Cohere). | | AI‑Assisted Editing | In‑place editing suggestions via LLM, integrated into the CLI or UI. |
The roadmap is community‑driven; contributors can propose new milestones via GitHub Issues or Discussions.
13. Conclusion (≈ 250 words)
memweave fills a critical niche in the AI ecosystem: a zero‑infra, async‑first, file‑based memory layer that is both powerful and practical. By storing knowledge as Markdown, it preserves human readability and version‑control friendliness. Its lightweight inverted index, fuzzy search, and Git‑style diffing enable agents to access and reason over context with low latency and no external dependencies.
Whether you’re a researcher building a personal knowledge base, a developer prototyping a conversational agent, or an organization that needs an auditable memory store, memweave offers a compelling trade‑off between simplicity and capability. The library’s modular architecture allows easy integration with LangChain, OpenAI embeddings, and other popular frameworks. Its async design makes it future‑proof as LLM calls become more I/O‑bound.
The community around memweave is growing, with real‑world projects ranging from PKM to compliance auditing. The roadmap promises to add persistence, distributed features, and richer UI, ensuring memweave stays relevant as the AI landscape evolves.
If you’re looking for a minimal, maintainable memory solution that lets you focus on building agents rather than plumbing, memweave is worth exploring. Install it today, experiment with the CLI, and watch your agents gain a persistent, searchable, and auditable memory that lives on disk and scales with your imagination.