Skip to main content

GoodMem integration for DSPy — a self-hosted memory backend for agents

Project description

dspy-goodmem

PyPI version Python versions License: MIT

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 using GoodMemRM as a retriever with ChainOfThought and SemanticF1 evaluation.
  • examples/react_agent_example.py — Agent-driven memory with dspy.ReAct and make_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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dspy_goodmem-0.1.0.tar.gz (30.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dspy_goodmem-0.1.0-py3-none-any.whl (16.6 kB view details)

Uploaded Python 3

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

Hashes for dspy_goodmem-0.1.0.tar.gz
Algorithm Hash digest
SHA256 e590f96176395b6e22fc54f1200be77c33e8f8e404327cbf4dee716d6d57b609
MD5 e5bd5cc1a2462a2add258e0f28251c76
BLAKE2b-256 64a8a455b35225cadea3913d6a706899262ff8933276f73af047d70bb77e7cb6

See more details on using hashes here.

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

Hashes for dspy_goodmem-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 67f91d8ca0f932be721995f49868843461d36504146b2b2b30dadb98347f5c28
MD5 7c726cd9347684652ef198ec1eef309f
BLAKE2b-256 0dc25e912f0fd14cd2b17dc1b221495b8a562135edaf530e6ad7a3a2d7537a70

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page