Skip to main content

goodmem-langchain

Use GoodMem from LangChain for document ingestion, retrieval, and agent memory. GoodMem handles storage, chunking, embeddings, and optional reranking.

Version 0.3 breaks compatibility with earlier releases; see CHANGELOG.md for migration.

Install and connect

Requires Python 3.10+, a running GoodMem server, an API key, and a space configured with an embedder.

pip install goodmem-langchain
export GOODMEM_BASE_URL="http://localhost:8080"
export GOODMEM_API_KEY="your-key"

Retrievers and tools read these variables, or take a configured goodmem.Goodmem as client=; you keep ownership of it.

Write Documents and retrieve

import os
from goodmem import Goodmem
from langchain_core.documents import Document
from goodmem_langchain import GoodMemRetriever, add_documents

space_id = "5f6b1c2e-8a4d-4e3b-9c7a-2d1e0f9a8b7c"  # your space's UUID
with Goodmem(
    base_url=os.environ["GOODMEM_BASE_URL"],
    api_key=os.environ["GOODMEM_API_KEY"],
) as client:
    memory_ids = add_documents(client, space_id, [
        Document(
            page_content="Project Cobalt's launch owner is Ada.",
            metadata={"source": "https://example.org/cobalt", "team": "blue"},
        )
    ])

retriever = GoodMemRetriever(space_ids=[space_id], k=5, metadata_filter={"team": "blue"})
for document in retriever.invoke("Who owns Cobalt's launch?"):
    print(document.page_content, document.metadata["source"])

add_documents batches text and metadata through the SDK and waits for indexing by default. Set wait=False for background ingestion, then use wait_for_memory(client, memory_id) when readiness matters. Optional Document IDs must be UUIDs; existing IDs produce conflicts. GoodMemIngestionError.created_memory_ids identifies successful writes if part of ingestion fails.

metadata_filter pairs must all match; values are escaped and typed. Build richer filters with goodmem_langchain.filters (all_of, compare, one_of); never format user input into filter. Empty results return immediately.

The retriever returns Documents with source metadata, memory/chunk/space IDs, and scores. It supports LCEL, callbacks, batching, per-call k, and ainvoke through LangChain's thread executor.

If a search hits a real problem (a reranker unavailable, a space unreachable), the Documents it found are still returned, each carrying metadata["goodmem_partial"] = True and metadata["goodmem_statuses"] saying why. A problem that left no Documents returns [] with a UserWarning and a warning log line, unlike a search that matched nothing. Neither case raises. Notices that carry no loss (FEATURE_DISABLED, LLM_CAPABILITY_INFERRED) are dropped; a status code this version does not know is reported as UNKNOWN.

For reranking, set reranker_id and optionally fetch_k=20. Reranking requires no LLM.

Give an agent a search tool

from langchain_core.tools import create_retriever_tool

tool = create_retriever_tool(
    retriever, "search_project_records", "Search project records.",
    response_format="content_and_artifact",
)

The agent supplies only a query. Spaces and filters remain configured by the developer. Retrieved Documents are available in ToolMessage.artifact for citations.

Other tools and development

The package also provides space/memory management tools. GoodMemRetrieveMemories returns SDK events, including chunks, optional summaries, and statuses. Tools use SDK data shapes and LangChain ToolException handling.

IDs must be UUIDs because the SDK puts them unescaped into URL paths. Model file uploads need GoodMemCreateMemory(upload_dir="/srv/uploads"), confined there, symlinks resolved.

See the smoke example for a complete workflow.

uv sync --all-groups
uv run pytest --disable-socket --allow-unix-socket tests/unit_tests
uv run ruff check .
uv run mypy .

Metadata

Release files for goodmem-langchain 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for goodmem-langchain 0.3.0
File Size Uploaded
goodmem_langchain-0.3.0.tar.gz 163.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for goodmem-langchain 0.3.0
File Interpreter ABI Platform
goodmem_langchain-0.3.0-py3-none-any.whl Python 3 none any Details

Total release size: 190.7 kB

Release files / goodmem_langchain-0.3.0.tar.gz

Download URL goodmem_langchain-0.3.0.tar.gz
Size 163.3 kB
Tags Source
SHA-256 checksum
How to use checksums
df6ede986afa8271399e508ec875e9a66d9cfeb69b06dbf0ec179482027a1ed5
BLAKE2b-256 checksum
How to use checksums
5eb763b68e5cc197edf7300fa34c857632bbc783ae6fe299a6c12a43f2f918d8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 29, 2026.

Transparency log

Release files / goodmem_langchain-0.3.0-py3-none-any.whl

Download URL goodmem_langchain-0.3.0-py3-none-any.whl
Size 27.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bf1fdb96ba78b0719bcdfdf01b68bf3d9bd8619fed9a051fa78fe58786371468
BLAKE2b-256 checksum
How to use checksums
f05cfa43fdeee1eaa9588c2435dd28e8f80803e1d3a045f0b62210ceda527b43
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 29, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.3.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page