ChromaDB Memory

ChromaAgentMemory is the built-in MemoryService implementation. It uses ChromaDB with the all-MiniLM-L6-v2 embedding model for semantic search.

Setup

from mango.integrations.chromadb import ChromaAgentMemory

# Persistent — survives restarts
memory = ChromaAgentMemory(persist_dir="./mango_memory")

# Ephemeral — for testing
memory = ChromaAgentMemory(persist_dir=":memory:")

# Custom collection name
memory = ChromaAgentMemory(
    persist_dir="./mango_memory",
    collection_name="my_project_memory",
)

Storage layout

Two ChromaDB collections are created:

CollectionStores
<name>Tool-usage memories (question → tool_name, tool_args, result_summary)
<name>_textFree-form text memories (glossary, domain notes)

Pre-load domain knowledge

# Business terminology
await memory.save_text("'active user' = user with order in last 90 days")
await memory.save_text("'revenue' = total_amount field in orders collection")

# Field semantics
await memory.save_text("status field: 1=pending, 2=shipped, 3=delivered, 4=cancelled")

# Relationships not detected automatically
await memory.save_text("orders.customer_ref references customers._id")

Inspect stored data

# How many entries
print(memory.count())

# Search tool-usage memories
entries = await memory.retrieve(
    "how many users signed up?",
    top_k=5,
    similarity_threshold=0.0,   # 0.0 = no filter
)
for e in entries:
    print(f"[{e.similarity:.2f}] {e.question}{e.tool_name}({e.tool_args})")

# Search text memories
texts = await memory.search_text("what does active user mean", top_k=3)
for t in texts:
    print(f"[{t.similarity:.2f}] {t.text}")

# Delete an entry
await memory.delete(entry_id)

Direct ChromaDB access (debug)

# Dump all stored tool-usage entries without similarity filter
result = memory._collection.get(include=["documents", "metadatas"])
for doc, meta in zip(result["documents"], result["metadatas"]):
    print(f"Q: {doc}")
    print(f"   tool={meta['tool_name']} args={meta['tool_args']}")

Similarity threshold

The default threshold is 0.6 (cosine similarity). Entries below this score are not injected as examples. Tune it on MangoAgent:

# More examples, lower quality bar
agent = MangoAgent(..., memory_top_k=5)

# Control threshold at retrieval time
entries = await memory.retrieve(question, top_k=3, similarity_threshold=0.75)