GoodMemGoodMem
IntegrationsAgent Frameworks

Stanford DSPy

Wrap GoodMem's RAG pipeline as a DSPy retriever and expose memory-lifecycle tools to dspy.ReAct agents.

Stable· Python

Overview

GoodMem is a self-hosted RAG system that handles the full retrieval pipeline — ingestion, chunking, embedding, storage, hybrid search, reranking, and summarization — server-side. This integration wraps it for DSPy: plug GoodMemRM into any pipeline through the standard dspy.Retrieve interface, or hand GoodMem's full memory lifecycle to a dspy.ReAct agent as callable tools. GoodMemClient is also exposed directly when you want raw control over the REST API.

Installation

pip install dspy-goodmem

The pip package is dspy-goodmem; the import name is dspy_goodmem. A running GoodMem server is required. Install the optional dspy-goodmem[examples] extra to load a .env file via python-dotenv when running the example scripts.

Configuration

VariableDescription
GOODMEM_BASE_URLBase URL of your GoodMem server (no /v1 suffix), e.g. https://your-goodmem-server.example.com.
GOODMEM_API_KEYAPI key used to authenticate requests.

The OPENAI_API_KEY environment variable is also needed when configuring an OpenAI model as the DSPy LM. GoodMemRM and GoodMemClient accept api_key, base_url, and verify_ssl arguments directly in code.

Quick start

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://your-goodmem-server.example.com",
    k=3,
)

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)

Local development. The example above uses a TLS-verified production URL. If you are running GoodMem locally with a self-signed certificate, use https://localhost:8080 and disable TLS verification with the client's verify-SSL option (see the Configuration table above). Keep TLS verification enabled for any deployed server.

Retrieval post-processing

GoodMem's retrieval call accepts these optional post-processing parameters (each framework exposes them under its own naming convention):

ParameterRangeDescription
reranker_idUUIDReranker model that reorders matched chunks by relevance.
llm_idUUIDLLM that generates a contextual answer (abstractReply) alongside the chunks.
relevance_threshold0–1Minimum relevance score for a result to be included.
llm_temperature0–2Sampling temperature for the LLM post-processor.
max_resultsintegerMaximum number of results to return.
chronological_resortbooleanRe-sort the final results by creation time instead of relevance.

Learn more

The full README, examples, and API reference are available on the PyPI package page.