GoodMem integration for DSPy — a self-hosted memory backend for agents
Project description
dspy-goodmem
GoodMem integration for DSPy — a self-hosted memory backend for RAG pipelines and agents.
Ships a DSPy retriever (GoodMemRM), a raw HTTP client (GoodMemClient), and a tool factory (make_goodmem_tools) that exposes GoodMem's full space/memory lifecycle to dspy.ReAct agents — not just retrieval.
Installation
pip install dspy-goodmem
You also need a running GoodMem server. See docs.goodmem.ai for setup.
Quick start
import dspy
from dspy_goodmem import GoodMemRM
# Configure your LM (any LiteLLM-supported provider works)
dspy.configure(lm=dspy.LM("openai/gpt-5-mini"))
# Create a retriever backed by GoodMem
rm = GoodMemRM(
space_ids=["<your-space-uuid>"],
api_key="gm_...",
base_url="https://localhost:8080",
k=3,
)
# Build a simple RAG module
class RAG(dspy.Module):
def __init__(self, retriever):
super().__init__()
self.retriever = retriever
self.respond = dspy.ChainOfThought("context, question -> response")
def forward(self, question):
passages = self.retriever(question)
context = "\n\n".join(p["long_text"] for p in passages)
return self.respond(context=context, question=question)
rag = RAG(retriever=rm)
print(rag(question="What are the Series B terms?").response)
What's included
| Export | Role |
|---|---|
GoodMemRM |
dspy.Retrieve subclass — returns dotdict({"long_text": ...}) passages for any DSPy pipeline |
GoodMemClient |
Low-level HTTP wrapper around all 11 GoodMem REST operations |
make_goodmem_tools |
Factory that produces 11 typed callables for dspy.Tool / dspy.ReAct |
Agent memory lifecycle
Unlike retriever-only integrations, make_goodmem_tools lets a dspy.ReAct agent manage its own memory — create spaces, store new memories, retrieve, update, and delete — without a human in the loop:
import dspy
from dspy_goodmem import GoodMemClient, make_goodmem_tools
client = GoodMemClient(api_key="gm_...", base_url="https://localhost:8080")
tools = [dspy.Tool(fn) for fn in make_goodmem_tools(client)]
agent = dspy.ReAct("task -> result", tools=tools)
agent(task="Remember that the user prefers Python over Java, then recall my language preferences.")
GoodMem features you gain
- Bring your own embedding model — OpenAI, Voyage AI, Cohere, vLLM, TEI, Llama.cpp, including fully local/offline models
- Hybrid search — combine dense and sparse embedders (e.g. MiniLM + SPLADE) in a single space with configurable weights
- Configurable chunking — chunk size, overlap, separators, and mode set per space and handled on the server
- File ingestion — upload PDFs, DOCX, images, and other formats without manual text extraction
- Metadata filtering — SQL-style filters with JSONPath extraction, date ranges, regex, and array membership
- Reranking — pluggable reranker models re-score results after retrieval
- Auto-summary — an LLM generates a consolidated answer from retrieved chunks at query time
- Deep Research mode — multiple iterative search rounds with query refinement for open-ended topics
- Self-hosted — runs entirely on your infrastructure, no external API calls or quotas
Full examples
Two end-to-end examples cover the main usage patterns:
examples/rag_pipeline_example.py— Classic RAG pipeline usingGoodMemRMas a retriever withChainOfThoughtandSemanticF1evaluation.examples/react_agent_example.py— Agent-driven memory withdspy.ReActandmake_goodmem_tools, covering multi-turn conversation, cross-agent persistence, metadata filtering, and trajectory inspection.
Both load a .env file from the repo root if python-dotenv is installed (pip install dspy-goodmem[examples]), otherwise they read environment variables directly.
export OPENAI_API_KEY="sk-..."
export GOODMEM_API_KEY="gm_..."
export GOODMEM_BASE_URL="https://localhost:8080"
python examples/rag_pipeline_example.py
# or
python examples/react_agent_example.py
Development
pip install -e .[dev]
pytest tests/ -v
63 mocked unit tests cover the client, retriever, and tool factory — no live server required.
Related
License
MIT — see LICENSE.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file dspy_goodmem-0.1.0.tar.gz.
File metadata
- Download URL: dspy_goodmem-0.1.0.tar.gz
- Upload date:
- Size: 30.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e590f96176395b6e22fc54f1200be77c33e8f8e404327cbf4dee716d6d57b609
|
|
| MD5 |
e5bd5cc1a2462a2add258e0f28251c76
|
|
| BLAKE2b-256 |
64a8a455b35225cadea3913d6a706899262ff8933276f73af047d70bb77e7cb6
|
File details
Details for the file dspy_goodmem-0.1.0-py3-none-any.whl.
File metadata
- Download URL: dspy_goodmem-0.1.0-py3-none-any.whl
- Upload date:
- Size: 16.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
67f91d8ca0f932be721995f49868843461d36504146b2b2b30dadb98347f5c28
|
|
| MD5 |
7c726cd9347684652ef198ec1eef309f
|
|
| BLAKE2b-256 |
0dc25e912f0fd14cd2b17dc1b221495b8a562135edaf530e6ad7a3a2d7537a70
|