GoodMem integration for DSPy
Project description
dspy-goodmem
GoodMem is a self-hosted RAG system which handles the full retrieval pipeline: ingestion, chunking, embedding, storage, hybrid search, reranking, and summarization. This package wraps it for DSPy so you can:
- Plug
GoodMemRMinto any DSPy pipeline through the standarddspy.Retrieveinterface. - Hand GoodMem's full memory lifecycle to a
dspy.ReActagent as callable tools. - Use
GoodMemClientdirectly when you want control over the REST API.
Install
pip install dspy-goodmem
A running GoodMem server is required. See the Quick Start for deployment instructions.
Retriever usage
import dspy
from dspy_goodmem import GoodMemRM
dspy.configure(lm=dspy.LM("openai/gpt-5-mini"))
rm = GoodMemRM(
space_ids=["<your-space-uuid>"],
api_key="gm_...",
base_url="https://localhost:8080",
k=3,
verify_ssl=False, # localhost self-signed cert; remove for a server with a valid TLS cert
)
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="Summarize what's in the knowledge base.").response)
Agent usage
make_goodmem_tools returns 11 plain callables covering every GoodMem operation: full CRUD for spaces, create/list/get/delete for memories, plus semantic retrieval and embedder discovery. Wrap them in dspy.Tool and a dspy.ReAct agent can manage its own memory end to end instead of only reading from it.
import dspy
from dspy_goodmem import GoodMemClient, make_goodmem_tools
dspy.configure(lm=dspy.LM("openai/gpt-5-mini"))
client = GoodMemClient(
api_key="gm_...",
base_url="https://localhost:8080",
verify_ssl=False, # localhost self-signed cert; remove for a server with a valid TLS cert
)
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 their language preferences.")
What's exported
| Export | Purpose |
|---|---|
GoodMemRM |
dspy.Retrieve subclass. Returns dotdict({"long_text": ...}) passages. |
GoodMemClient |
HTTP wrapper around the GoodMem REST API. |
make_goodmem_tools |
Factory that produces typed callables for dspy.Tool and dspy.ReAct. |
Examples
Two end-to-end scripts live in examples/:
rag_pipeline_example.pyrunsGoodMemRMthroughChainOfThoughtand scores the pipeline withSemanticF1.react_agent_example.pyexercises the ReAct tools across four scenarios: multi-turn conversation, cross-agent persistence, metadata-tagged filtering, and trajectory inspection.
Both scripts load a .env file at 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
python examples/react_agent_example.py
Why GoodMem
GoodMem does the heavy lifting server side, so you don't ship an embedding pipeline with your DSPy app:
- Supports OpenAI, Voyage, Cohere, vLLM, TEI, and Llama.cpp as embedders, including fully local models.
- Hybrid search combining dense and sparse embedders, with configurable weights per space.
- Per-space chunking config: size, overlap, separators.
- Native ingestion for plain text, PDFs, Word documents, images, spreadsheets, and other formats.
- Metadata filters with JSONPath extraction, regex, and date ranges.
- Reranking and auto-summary pipelines configurable per request.
- Deep Research mode runs multiple iterative search rounds with query refinement for complex and open-ended topics.
Everything runs on your own infrastructure, so documents and queries never leave your network.
Development
pip install -e ".[dev]"
pytest tests/ -v
63 mocked unit tests cover the client, retriever, and tool factory. No live server required.
Links
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.1.tar.gz.
File metadata
- Download URL: dspy_goodmem-0.1.1.tar.gz
- Upload date:
- Size: 29.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
795bec089025ee73a2cd73421c33940388e55363737cc2221a8bfff18d25a9e3
|
|
| MD5 |
941857d280dff3f40a52221871b2a514
|
|
| BLAKE2b-256 |
3ec5f7f61099cb35ec6f91bc52025bbb3bd301620e4f1198312d18494bb3b25f
|
File details
Details for the file dspy_goodmem-0.1.1-py3-none-any.whl.
File metadata
- Download URL: dspy_goodmem-0.1.1-py3-none-any.whl
- Upload date:
- Size: 16.5 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 |
76fb439a5ec1c40a8e154753f6bdc69a1f85ad9ba19f93af863f8cc4e1af39b4
|
|
| MD5 |
c30f32f90329e27caf087013d744bc07
|
|
| BLAKE2b-256 |
a11cf63773aaf0a2c6c1f506c599f228364f452e12f409ce1c64a3b396034cbd
|