Skip to main content

LangGraph BaseStore implementation backed by OpenSearch with Pydantic configuration.

Project description

LangGraph OpenSearch Store

LangGraph-compatible BaseStore that persists agent long-term memory inside OpenSearch 3.x. Configuration uses pydantic-settings, so environment variables are validated as soon as the package imports. See docs/CODE_EXAMPLES.md for the high-level architecture, docs/OPS_GUIDE.md for migrations/operations, and docs/CONTRACT_TESTS.md for parity testing instructions.

TL;DR

uv pip install langgraph-opensearch-store

or just use pip: pip install langgraph-opensearch-store

Development Prerequisites

  • uv ≥ 0.6
  • Python 3.11+ (uv can install/manage it automatically)
  • OpenSearch 3.x cluster (local tarball/Homebrew or Amazon OpenSearch Service)

Quick Start

# 1) Install uv once per machine (if needed)
curl -LsSf https://astral.sh/uv/install.sh | sh

# 2) Initialize the project & tooling (pyproject already present)
uv venv
source .venv/bin/activate
uv sync --dev

# 3) Install dependencies
# uv sync --all-extras

# 4) Provide connection settings
cp .env.example .env
# → edit .env to match your OpenSearch deployment
#   - set `OPENSEARCH_VERIFY_CERTS=true` for prod clusters
#   - set `OPENSEARCH_IGNORE_SSL_CERTS=true` only for dev/self-signed endpoints

# 5) Run quality gates
uv run ruff check .
uv run pyright
uv run pytest

# 6) Exercise sample code (venv must stay active)
uv run python examples/basic_usage.py

# 7) Build
uv build

Tip: Always source .venv/bin/activate (or prefix commands with uv run) before running Python scripts so the managed interpreter and dependencies load correctly.

Programmatic Configuration (no .env required)

If you install the package via pip and prefer not to maintain a .env file, instantiate settings directly:

from langchain_openai import OpenAIEmbeddings
from langgraph_opensearch_store import OpenSearchStore

store = OpenSearchStore.from_params(
    hosts="https://search-example.us-east-1.es.amazonaws.com",
    auth_mode="sigv4",
    aws_region="us-east-1",
    index_prefix="agent_mem",
    ignore_ssl_certs=False,
    embeddings=OpenAIEmbeddings(model="text-embedding-3-small"),
)
store.setup()

Pass any field from Settings as a keyword argument; defaults mirror the .env example.

Project Folder Structure

  • src/langgraph_opensearch_store/Settings, OpenSearch client factory, schema helpers, OpenSearchStore, TemplateManager, and the MemorySaver bridge.
  • examples/ — runnable scripts mirroring docs/CODE_EXAMPLES.md.
  • tests/ — unit tests for the settings model + store wiring.
  • docs/ — research notes and reference snippets for agents.

Namespace Metadata & Stats

OpenSearchStore.setup() now installs versioned templates plus two indices:

  • Data index (<prefix>-data alias) storing all documents across namespaces.
  • Namespace index (<prefix>-namespace) tracking doc counts and timestamps for store.list_namespaces() + store.get_stats().

This means you can introspect namespaces the same way you would with the Postgres store:

store.list_namespaces(prefix=("prefs",))
store.get_stats()  # => {"total_items": ..., "namespace_count": ...}

Search Modes & TTL

  • search_mode: auto (default), text, vector, or hybrid. Auto uses hybrid when embeddings + query are available. Configure via .env (OPENSEARCH_SEARCH_MODE) or OpenSearchStore.from_params(...).
  • search_num_candidates influences Lucene kNN recall; the store now maps this value to method_parameters.ef_search so OpenSearch 3.x queries stay valid while still letting you widen the candidate pool. search_similarity_threshold remains available for score cutoffs.
  • Namespace + metadata filters are injected directly into the kNN clause, so Lucene/Faiss can short-circuit on filtered subsets without a post-filter penalty.
  • TTL support is enabled by default when you pass ttl to store.put(...) or set OPENSEARCH_TTL_MINUTES_DEFAULT. Expired docs are filtered automatically during get/search, and the helper store.ttl_manager.run_once() deletes all expired docs via delete-by-query.
store = OpenSearchStore.from_params(
    hosts="http://localhost:9200",
    search_mode="hybrid",
    search_num_candidates=400,   # mapped to ef_search under the hood
    ttl_minutes_default=1440,
)
store.setup()
store.put(("prefs",), "favorite_color", {"text": "blue"}, ttl=60)
store.search(("prefs",), query="blue", limit=3, metadata_filter={"source": "profile"})
store.ttl_manager.run_once()

Operations CLI

The package exposes a CLI (installed as langgraph-opensearch) for common maintenance tasks. Commands accept the same flags/env vars as OpenSearchStore.from_params (e.g., --auth-mode sigv4).

# Health & stats
langgraph-opensearch --conn "https://user:pass@localhost:9200" health
langgraph-opensearch --conn $OPENSEARCH_CONN stats
langgraph-opensearch --conn $OPENSEARCH_CONN ttl-sweep --batch-size 500

# Template migrations / alias rollovers
langgraph-opensearch --conn $OPENSEARCH_CONN migrate --rollover
langgraph-opensearch --conn $OPENSEARCH_CONN migrate --no-rollover --new-index my-data-v02

# Snapshot management (fs repo must exist on the cluster)
langgraph-opensearch --conn $OPENSEARCH_CONN snapshots create --repository langgraph --snapshot nightly --no-wait
langgraph-opensearch --conn $OPENSEARCH_CONN snapshots delete --repository langgraph --snapshot nightly

The GitHub Actions contract-tests job runs migrate and snapshot smoke tests against the containerized OpenSearch service so regressions in the CLI are caught automatically.

Observability & Metrics

  • Set OPENSEARCH_LOG_OPERATIONS=false to silence operation logs.
  • Set OPENSEARCH_METRICS_ENABLED=true to emit simple JSON metrics via the langgraph.opensearch.store.metrics logger (wire it into Prometheus/Otel via your logging pipeline).
  • store.get_health() returns cluster info, template version, and TTL sweeper state for dashboards.

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

langgraph_opensearch_store-0.1.8.tar.gz (15.4 kB view details)

Uploaded Source

Built Distribution

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

langgraph_opensearch_store-0.1.8-py3-none-any.whl (19.0 kB view details)

Uploaded Python 3

File details

Details for the file langgraph_opensearch_store-0.1.8.tar.gz.

File metadata

  • Download URL: langgraph_opensearch_store-0.1.8.tar.gz
  • Upload date:
  • Size: 15.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.9 {"installer":{"name":"uv","version":"0.9.9"},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for langgraph_opensearch_store-0.1.8.tar.gz
Algorithm Hash digest
SHA256 0445cf47fcf69e2c09e700f501606b82adc1a944c5b7c95527d346ab2ab204fb
MD5 536237869ce802111aa5e3b6809e191a
BLAKE2b-256 5d8fc1410e8ef33713012d96d810bc3a2dfa440b0680160a15bec9e1b97880bc

See more details on using hashes here.

File details

Details for the file langgraph_opensearch_store-0.1.8-py3-none-any.whl.

File metadata

  • Download URL: langgraph_opensearch_store-0.1.8-py3-none-any.whl
  • Upload date:
  • Size: 19.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.9 {"installer":{"name":"uv","version":"0.9.9"},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for langgraph_opensearch_store-0.1.8-py3-none-any.whl
Algorithm Hash digest
SHA256 bc363096f0ac1d798e034e988f2eee09f584a7a01559c6c68f66f6cf79b586e3
MD5 55e13e898e8e7177cbd0bfde9ffb8ffd
BLAKE2b-256 0d31e349ed58f22c1622be9ce1afcd9cbdac0d62ffc7fd6edbb3c3094ebefe8a

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