Connect To An Existing SpaceΒΆ

This is the best starting workflow for most LangChain users.

Choose this path when you already have a GoodMem space_id and you want to:

  • write texts or LangChain Document values into that space

  • run semantic retrieval without managing embeddings locally

  • keep the LangChain integration as thin as possible

Important behavior to keep in mind while you read the example below:

  • each write call creates one or more GoodMem memories

  • each search result is a chunk-level LangChain Document

  • Document.id in search results is the GoodMem chunk ID, not the memory ID

  • metadata filters operate on the stored memory metadata using the GoodMem filter language, for example val('$.lang') = 'en'

This example is the runnable source of truth for the most common workflow: bind the vector store to an existing GoodMem space, add multiple documents, then run chunk-level semantic retrieval with and without scores.

Prerequisites:

  • install the package with pip install -e .

  • provide a valid GoodMem API key and base URL

  • create or identify a GoodMem space ahead of time

  • obtain that space_id from the GoodMem SDK, CLI, or web console, or use GoodMemVectorStore.create(...) in a separate setup step

Run the example by editing the placeholder connection values and space_id, then execute:

./.venv/bin/python examples/basic_semantic_search.py

Expected output:

  • created memory IDs from add_documents(...)

  • one chunk-level retrieval listing whose Document.id values are chunk IDs

  • one scored retrieval listing

The filter examples use the documented GoodMem filter language. In particular, memory metadata fields are read with expressions such as val('$.lang') = 'en'.

Search visibility is eventually consistent. Fresh writes may not appear in semantic retrieval immediately after the add call returns.