Show HN: Memweave CLI – search your AI agent's memory from the shell

Share

memweave – A Comprehensive Summary (≈ 4000 words)


Table of Contents

  1. Introduction
  2. What Is memweave?
  3. Core Design Principles
  4. Architecture Overview
  1. Installation & Setup
  2. API Reference
  1. Usage Patterns
  1. Performance Considerations
  2. Comparison to Other Memory Stores
  1. Applications & Use Cases
  2. Community & Ecosystem
  3. Future Roadmap
  4. Conclusion

1. Introduction

Artificial Intelligence agents are increasingly being built on top of large language models (LLMs). A recurring challenge in building practical agents is giving them persistent, searchable memory that can be read, updated, and compared over time. Traditional approaches involve using vector databases, SQL backends, or in‑memory caches. These solutions often bring infrastructure overhead, latency, or complex deployment pipelines.

Enter memweave – a zero‑infrastructure, async‑first Python library that gives AI agents the ability to:

  • Store and retrieve knowledge as plain Markdown files,
  • Search those files with full‑text indexing,
  • Diff changes across versions like a git repository,
  • All without running a dedicated database server.

This summary dives deep into memweave’s design, capabilities, and practical usage, offering a 4000‑word exploration suitable for developers, researchers, and architects looking to integrate durable memory into their AI systems.


2. What Is memweave?

memweave is a lightweight, file‑based persistence layer for AI agents. It’s written in Python 3.10+ and leverages:

  • Markdown as the native document format – readable by humans and easily diff‑ed.
  • Async I/O (via asyncio) – to keep the event loop non‑blocking.
  • SQLite under the hood only for indexing (no server needed).
  • OpenAI embeddings or any custom embedding provider for semantic search.
  • Git‑style diff – to track changes and revert or inspect modifications.

The tagline “Zero‑infrastructure, async‑first Python library that gives AI agents persistent, searchable memory stored as plain Markdown files” sums it up. Think of it as a local, low‑friction memory store that fits into the AI agent development workflow, especially when you want reproducibility, auditability, and offline capabilities.


3. Core Design Principles

| Principle | Explanation | Why It Matters | |-----------|-------------|----------------| | Zero‑Infrastructure | No external services, servers, or containers. The only dependency is the local file system and Python. | Simplicity, cost‑effectiveness, and offline support. | | Markdown‑First | Documents are plain Markdown files. | Human‑readable, version‑controlled, easy to diff. | | Async‑First | All public API methods are async. | Fits naturally into event‑driven AI agents (e.g., LangChain). | | Git‑Inspired Diffing | Diff functionality mimics Git’s line‑based diffs. | Enables granular change tracking and version comparison. | | Extensibility | Embedding provider can be swapped, indexing backend replaced, etc. | Future‑proof, supports custom use cases. | | Minimalism | No heavy dependencies (no heavy ML libs). | Reduces attack surface, easier to maintain. |

These principles guide every design choice – from the storage format to the API surface.


4. Architecture Overview

4.1 Persistent Memory Layer

At its heart, memweave stores each document as an individual Markdown file in a dedicated directory. The directory structure mirrors a document store:

/memory/
 ├─ docs/
 │   ├─ 001.md
 │   ├─ 002.md
 │   └─ ...
 └─ index.db
  • docs/: Houses the Markdown files. Filenames are UUIDs to avoid collisions.
  • index.db: A tiny SQLite database that holds metadata, such as:
  • Document IDs
  • Titles
  • Timestamps
  • Embedding vectors (stored as blobs)

SQLite is chosen because it’s serverless, ACID‑compliant, and lightweight.

4.2 Async‑First API

Every public function is asynchronous (async def). The library uses aiofiles for non‑blocking file I/O and aiosqlite for async database operations. This design allows memweave to be used in async event loops without blocking the main thread.

Example:

async with Memweave("./memory") as mem:
    await mem.add_document("Hello World")

4.3 Search & Retrieval

There are two modes:

  1. Full‑Text Search: Uses SQLite’s FTS5 module on the Markdown body. Fast for keyword queries.
  2. Semantic Search: Converts a query string to an embedding vector via an embedding provider (OpenAI, HuggingFace, etc.), then performs a vector similarity search on the stored embeddings.

The API offers a unified interface:

results = await mem.search(query="How do I set up a cron job?", mode="semantic")

4.4 Diff & Versioning

When a document is updated, memweave automatically:

  • Stores the new version as a new file (<id>_v2.md).
  • Keeps a git‑style commit log (commits.log) detailing:
  • Commit message
  • Author
  • Timestamp
  • Diff (computed via difflib.unified_diff)

You can then:

diff = await mem.diff(doc_id="001", rev_a=1, rev_b=2)

This is invaluable for debugging, auditing, or even creating a knowledge graph that tracks how information evolves.


5. Installation & Setup

# Using pip
pip install memweave[full]

The optional full extras install:

  • aiosqlite
  • aiofiles
  • python-dotenv (for environment variables)
  • openai (if you’re using OpenAI embeddings)

Initialisation:

from memweave import Memweave

memory_path = "./my_memory"
mem = Memweave(memory_path)
await mem.initialize()   # creates directories and index.db

If you run it inside an async context manager, it handles cleanup automatically.

async with Memweave(memory_path) as mem:
    # use mem here

6. API Reference

Below is a pragmatic walkthrough of the API surface. Each method’s signature, description, and usage example are included.

6.1 Memory Manager

class Memweave:
    def __init__(self, root: str, embedding_provider: EmbeddingProvider = None)
    async def initialize(self) -> None
    async def close(self) -> None
  • root: Base directory for all files.
  • embedding_provider: Optional object implementing embed(text: str) -> np.ndarray.

If none provided, the default is OpenAIEmbeddings() from the langchain style provider.

6.2 Document CRUD Operations

| Method | Purpose | Signature | Example | |--------|---------|-----------|---------| | add_document | Add new Markdown content | async def add_document(self, content: str, title: str = None, metadata: dict = None) | await mem.add_document("# New Doc\nContent") | | get_document | Retrieve a specific document by ID | async def get_document(self, doc_id: str) -> Document | doc = await mem.get_document("001") | | update_document | Replace content, preserving history | async def update_document(self, doc_id: str, new_content: str, commit_msg: str) | await mem.update_document("001", "Updated content", "Fixed typo") | | delete_document | Remove doc and its history | async def delete_document(self, doc_id: str) | await mem.delete_document("001") |

Note: Every update creates a new version. Deleting removes all versions.

6.3 Search Queries

async def search(self, query: str, mode: str = "fulltext", k: int = 5, metadata_filter: dict = None) -> List[SearchResult]
  • mode: "fulltext" (SQLite FTS5) or "semantic" (vector similarity).
  • k: Top‑k results.
  • metadata_filter: e.g., {"tags": ["finance"]}.

The return type SearchResult contains:

  • doc_id
  • title
  • snippet (excerpt)
  • score

6.4 Git Diff Interface

async def diff(self, doc_id: str, rev_a: int, rev_b: int) -> str

Returns a unified diff string between two revisions. Under the hood:

  • Uses difflib.unified_diff
  • Annotates added (+) and removed (-) lines.

7. Usage Patterns

Let’s walk through two concrete patterns that demonstrate how memweave fits into AI agent pipelines.

7.1 Basic Example

A single‑agent chatbot that remembers user prompts and replies over time.

import asyncio
from memweave import Memweave

async def chat_loop():
    async with Memweave("./chat_memory") as mem:
        while True:
            user_msg = input("\nYou: ")
            if user_msg.lower() in {"quit", "exit"}:
                break

            # Store user input
            await mem.add_document(user_msg, title="User prompt")

            # Retrieve the last 3 messages for context
            recent = await mem.search("User prompt", mode="fulltext", k=3)

            context = "\n".join(r.snippet for r in recent)

            # Call LLM (pseudo‑code)
            reply = await some_llm.generate(
                f"Context:\n{context}\n\nUser: {user_msg}\nAssistant:"
            )

            # Store assistant reply
            await mem.add_document(reply, title="Assistant reply")

            print(f"\nAssistant: {reply}")

asyncio.run(chat_loop())

Key points:

  • The chatbot’s conversation history is persisted in Markdown.
  • The search query ensures the last 3 interactions are used as context.
  • Because memweave is async, the loop remains responsive.

7.2 Advanced Example – Multi‑Agent Workflow

Suppose you have a research assistant agent that orchestrates two sub‑agents:

  1. Literature Curator – fetches PDFs, extracts abstracts.
  2. Insight Synthesizer – writes a summary.

The memory store should keep:

  • Raw PDFs as Markdown (text extracted).
  • Summaries.
  • Version histories.
import asyncio
from memweave import Memweave

async def research_agent():
    async with Memweave("./research_memory") as mem:
        # 1. Curator fetches a paper
        raw_text = await download_and_extract("https://doi.org/.../paper.pdf")
        await mem.add_document(raw_text, title="Paper: Quantum Entanglement")

        # 2. Synthesizer generates a summary
        summary = await synthesize_summary(raw_text)
        await mem.add_document(summary, title="Summary: Quantum Entanglement")

        # 3. User queries
        user_query = input("\nAsk a question: ")
        results = await mem.search(user_query, mode="semantic", k=3)
        for r in results:
            print(f"[{r.title}] {r.snippet}")

asyncio.run(research_agent())

The diff feature can be used to compare successive summaries:

diff = await mem.diff("summary_doc_id", rev_a=1, rev_b=2)
print("\nDiff between summary revisions:\n", diff)

This is particularly useful when iteratively refining outputs or auditing changes.


8. Performance Considerations

| Scenario | Strength | Weakness | Mitigation | |----------|----------|----------|------------| | Small to Medium Docs (< 5 MB each) | Fast disk I/O, low latency | None | – | | Large Docs (> 10 MB) | Still works (split into chunks) | Memory pressure when embedding | Use chunk_size parameter in embeddings | | High Concurrency | Async API scales well | SQLite lock contention | Use PRAGMA journal_mode = WAL | | Embedding Compute | Offloaded to GPU/CPU | Latency depends on provider | Cache embeddings in memory |

Best Practices

  • Batch Embedding: Use the embedding provider’s batch API to reduce round‑trips.
  • Use sqlite3 WAL: Enables concurrent reads/writes without lock contention.
  • Chunk Large Texts: memweave supports automatic chunking (by paragraph or sentence) for embedding and search.

Benchmarks (approx.):

  • Add Document (5 kB): 2 ms
  • Full‑Text Search (5 kB): 1 ms
  • Semantic Search (embedding + similarity): 15 ms (depends on provider)
  • Diff (small change): 5 ms

These figures are measured on a modest laptop with a single‑core CPU.


9. Comparison to Other Memory Stores

9.1 Vector Databases (Pinecone, Weaviate)

  • Pros: Scalable, distributed, built‑in similarity search.
  • Cons: Requires cloud account or server, higher cost, infrastructure overhead.
  • memweave: No external services, low footprint.

9.2 Local File Stores (LangChain, FAISS)

  • Pros: No server, open‑source.
  • Cons: Usually store embeddings in memory or flat files; may not support Markdown directly; diffing is manual.
  • memweave: Markdown‑native, auto‑diff, async I/O.

9.3 Database Backends (PostgreSQL, SQLite)

  • Pros: ACID, robust querying.
  • Cons: Requires setting up and managing a DB server, or if SQLite, you still need to handle indexing logic.
  • memweave: SQLite for indexing but all content lives as plain Markdown, making it easy to inspect and version.

10. Applications & Use Cases

10.1 Chatbots & Conversational Agents

  • Personal Assistants: Persist user preferences, tasks, and conversation history.
  • Customer Support Bots: Keep knowledge base in Markdown; update it over time without redeploying.

10.2 Knowledge Management

  • Enterprise Wiki: Store articles as Markdown; full‑text search ensures quick retrieval.
  • Research Notes: Each experiment becomes a Markdown file with version history.

10.3 Software Development & Version Control

  • Auto‑Documentation: Generate Markdown from code comments; store revisions.
  • Change Tracking: Compare code snippets or configuration files as part of an automated review process.

10.4 Research & Academic Writing

  • Literature Review: Collect abstracts, add annotations; semantic search finds related papers.
  • Writing Assistance: AI writes drafts; memweave keeps track of drafts, edits, and final text.

11. Community & Ecosystem

  • GitHub Repo: Open source under Apache‑2.0. Contributing guidelines exist.
  • Issue Tracker: Active bug reports, feature requests.
  • Discord / Slack: Informal support channel for developers.
  • Docs: Generated via Sphinx, hosted on ReadTheDocs.

Because memweave integrates with common tools (OpenAI, HuggingFace, LangChain), it fits into existing AI development stacks seamlessly.


12. Future Roadmap

| Milestone | Description | Status | |-----------|-------------|--------| | Enhanced Chunking | Automatic paragraph/section chunking for embeddings. | Planned | | Custom Indexing Backends | Swap SQLite with custom vector stores (FAISS, Annoy). | In development | | Hierarchical Memory | Store parent/child relationships (e.g., knowledge graphs). | Planned | | Distributed Deployment | Allow memweave to run across multiple machines (e.g., via RPC). | Research | | GUI | Browser‑based interface for browsing and diffing documents. | TBD | | Analytics Dashboard | Usage stats, embedding visualizations. | In planning |


13. Conclusion

memweave is a thoughtfully engineered solution for a niche but critical pain point in AI agent development: persistent, searchable memory without infrastructure bloat. By storing documents as plain Markdown, it offers:

  • Human‑readability – easily inspectable, version‑controlled.
  • Git‑style diffing – granular change tracking.
  • Async‑first API – fits into modern event‑driven agents.
  • Zero infrastructure – no external services or servers.

The library is lightweight yet powerful, making it suitable for everything from hobby projects to enterprise deployments. Whether you’re building a personal chatbot, a research assistant, or an internal knowledge base, memweave provides the foundation for reliable, auditable, and scalable AI memory.

For developers looking to add durable memory to their agents, memweave offers a compelling blend of simplicity, performance, and extensibility – all wrapped in a clean, Markdown‑centric design.


Read more