Skip to content

v0.4.0

Choose a tag to compare

@johnymontana johnymontana released this 21 May 12:21
· 334 commits to main since this release
9ae78c7

The "hosted backend" release. Headline feature is NAMS (Neo4j Agent Memory Service) backend support — write once against MemoryClient, choose between local bolt-to-Neo4j or the hosted REST service at config time. The change is purely additive — existing v0.3.x code keeps working unchanged on bolt.

Added

  • NAMS backend — MemorySettings(backend="nams", nams=NamsConfig(api_key=...)) routes every client.short_term, client.long_term, client.reasoning, and client.query call to the hosted REST API at https://memory.neo4jlabs.com/v1 (default endpoint, overridable). SPEC tier conformance targets Bronze, Silver, Gold, and Platinum.

  • neo4j_agent_memory.nams package — new public surface:

    • NamsConfig — endpoint, api_key (SecretStr), timeout, retries, headers, validate_on_connect, transport_mode.
    • AuthProvider Protocol + StaticApiKeyAuth (Authorization: Bearer {api_key}).
    • HttpTransport — httpx-based async client with retry policy (429 honors Retry-After, 5xx + network errors retried with exponential backoff), structured error mapping, and OpenTelemetry-style span attributes.
    • Auto-protocol detection: /v\d+-shaped endpoints → REST; otherwise TCK bridge protocol (POST /{snake_case_method}).
    • NamsBackend — composition root that owns the transport + three memory implementations + Cypher accessor. Used by MemoryClient.connect() when backend == "nams".
  • neo4j_agent_memory.core.protocols — three new @runtime_checkable Protocols (ShortTermProtocol, LongTermProtocol, ReasoningProtocol) plus CypherQueryProtocol. Existing ShortTermMemory/LongTermMemory/ReasoningMemory bolt classes structurally satisfy them; new NamsShortTermMemory/NamsLongTermMemory/NamsReasoningMemory implement them over HTTP.

  • client.query.cypher(query, params) — unified read-only Cypher accessor. Works on both backends. On bolt, forwards to Neo4jClient.execute_read; on NAMS, forwards to POST /v1/query (Platinum). Read-only enforcement uses a shared is_read_only_query validator.

  • Platinum-tier methods on client.long_term and client.short_term:

    • set_entity_feedback(entity_id, feedback, user_identifier=...)
    • get_entity_history(entity_id, limit=...)
    • get_entity_provenance(entity_id) (Gold; available on bolt and NAMS)
    • bulk_add_messages(session_id, messages)
    • get_observations(session_id, limit=...)
    • get_reflections(session_id, limit=...)
    • create_conversation(session_id, ...)
    • list_conversations(user_identifier=..., limit=...)

    NAMS implements them via REST; bolt is missing the Platinum surface and raises NotSupportedError at call time.

  • New exceptions in neo4j_agent_memory.core.exceptions:

    • TransportError(ConnectionError) — HTTP transport failures (5xx, network).
    • AuthenticationError(MemoryError) — 401/403.
    • NotSupportedError(MemoryError) — structured with backend, method, workaround.
    • RateLimitError(MemoryError) — 429, carries retry_after.
    • ValidationError(MemoryError) — 400, carries details.

    Existing except ConnectionError blocks still catch transport failures (since TransportError is a subclass).

  • NAMS-flavored framework helpers:

    • integrations.pydantic_ai.nams_memory_tools(memory) — base tools + Platinum tools (set_entity_feedback, get_entity_history, get_entity_provenance, cypher_query) as Pydantic AI tools.
    • integrations.strands.nams_context_graph_tools(endpoint=..., api_key=...) — Strands @tool functions for NAMS Platinum operations. Auto-reads MEMORY_API_KEY/MEMORY_ENDPOINT from env.
  • MCP server:

    • Four new Platinum tools (memory_set_entity_feedback, memory_get_entity_history, memory_get_entity_provenance, memory_get_reflections) registered automatically when the underlying MemoryClient uses backend == "nams".
    • register_tools(mcp, *, profile, register_platinum) parameter.
  • CLI — neo4j-agent-memory mcp serve accepts new flags:

    • --backend {bolt,nams} (env: NAM_BACKEND)
    • --api-key (env: MEMORY_API_KEY)
    • --endpoint (env: MEMORY_ENDPOINT)
  • Environment variables — MEMORY_API_KEY and MEMORY_ENDPOINT are recognized by MemorySettings. When MEMORY_API_KEY is set and backend is unspecified, the backend defaults to NAMS (otherwise bolt — preserving the historical default).

  • Documentation:

    • explanation/backends.adoc — bolt vs NAMS trade-offs and feature matrix.
    • how-to/use-nams.adoc — first-time NAMS setup.
    • how-to/migrate-to-nams.adoc — porting bolt code; full NotSupportedError table.
    • tutorials/nams-quickstart.adoc — 5-minute walkthrough.
  • Examples:

    • examples/nams-quickstart/ — minimal end-to-end NAMS usage.
    • examples/nams-langchain/ — LangChain ConversationChain backed by NAMS.
    • examples/nams-fastapi/ — FastAPI app with lifespan-managed NAMS client.
  • Tests — tests/unit/nams/ (12 test files, respx-based, 320+ tests). tests/integration/nams/ scaffold for TCK conformance suite (Bronze/Silver/Gold/Platinum) once the TCK reference Docker image is available.

Changed

  • MemoryClient.connect() dispatches on MemorySettings.backend. When unset, NAMS if MEMORY_API_KEY is in the environment, otherwise bolt.
  • client.graph raises NotSupportedError on NAMS — use client.query.cypher() for portable read-only queries. On bolt, returns a deprecation proxy that emits a one-time DeprecationWarning on execute_read calls; execute_write continues to work without deprecation.
  • client.users, client.buffered, client.consolidation — on NAMS, accessors return a _NamsUnsupported sentinel that raises NotSupportedError with workaround hints on any method call.
  • client.schema — on NAMS, returns a _NamsUnsupported sentinel (adopt_existing_graph and other schema operations are server-managed by NAMS).
  • client.get_stats, client.get_graph, client.get_locations — raise NotSupportedError on NAMS (rely on bolt-specific Cypher; use client.query.cypher() with a custom query).
  • MCP graph_query tool, _get_entity_neighbors helper, memory://graph/stats resource — migrated from client.graph.execute_read to client.query.cypher. Now portable across both backends.
  • Strands context_graph_tools internal Cypher, AgentCore HybridMemoryProvider._enrich_with_relationships, and EvalMemory._eval_audit — same migration. All work on both backends.

Deprecated

  • client.graph.execute_read — use client.query.cypher for portable read-only queries. Emits one-time DeprecationWarning per process. Scheduled for removal in v0.6.0.

Migration

Existing v0.3.x users:

  • Stay on bolt → no code changes required.
  • Switch to NAMS → set one env var:
    export MEMORY_API_KEY=nams_xxxxx
    MemoryClient() now talks to NAMS. Methods that don't apply (geocoding, enrichment, deduplication knobs) emit a single UserWarning at connect() time listing the inactive layers.
  • For custom Cypher:
    # v0.3 (deprecated, still works on bolt)
    results = await client.graph.execute_read("MATCH (n:Entity) RETURN n LIMIT 10")
    # v0.4 (works on both backends)
    results = await client.query.cypher("MATCH (n:Entity) RETURN n LIMIT 10")

See docs/.../how-to/migrate-to-nams.adoc for the full migration cookbook and NotSupportedError reference table.

Backward compatibility

  • Every public class/function from v0.3.x is importable unchanged.
  • All existing examples and integration tests pass on bolt without modification.
  • The SPEC-aligned method names (add_message, add_entity, start_trace, ...) were already present in v0.3 — they were the source for the SPEC.
  • BaseMemory[T] ABC stays as the bolt base class; the new Protocols supplement it without replacing it.

[0.3.0] - 2026-05-12

The "bring your own model" release. Headline feature is pluggable LLM and embedding providers — Anthropic, Bedrock, Vertex AI, local sentence-transformers, and 100+ others via LiteLLM now slot in alongside OpenAI through a single Protocol. Existing v0.2.x code keeps working with a one-time DeprecationWarning; the legacy EmbeddingConfig/LLMConfig types are removed in v0.5.0.

Added

  • neo4j_agent_memory.llm package — new public surface for the Provider Protocol. Three @runtime_checkable Protocols:
    • LLMProvider — chat completions (Bronze tier).
    • StructuredExtractor — validated Pydantic outputs (Silver tier).
    • EmbeddingProvider — text embeddings (Bronze tier).
      Plus types (ChatMessage, Completion, Usage), a provider-agnostic exception hierarchy (ProviderError, ProviderRateLimitError, ProviderTimeoutError, ProviderAuthError, ProviderInvalidRequestError, ProviderServiceError, StructuredExtractionError, EmbeddingDimensionMismatchError), a defaults lookup (EMBEDDING_DIMENSIONS, lookup_embedding_dimensions), the schema-aligned retry helper (schema_aligned_extract), and the factory (from_provider).
  • Native adapters — OpenAIProvider, OpenAIEmbeddingProvider, AnthropicProvider (with optional Anthropic prompt-caching via cache_system=True), BedrockProvider, BedrockEmbeddingProvider, SentenceTransformersProvider, VertexAIEmbeddingProvider, InstructorProvider.
  • Universal adapter — LiteLLMProvider and LiteLLMEmbeddingProvider cover 100+ providers (Cohere, Voyage, Groq, Together, Mistral, Ollama, OpenRouter, ...).
  • from_provider("provider/model", ...) string-shorthand factory with native-first resolution: when both a native adapter and LiteLLM are installed, the native adapter wins. Override with prefer_litellm=True. Unknown-extra errors include an actionable install hint.
  • Vector index dimension validation — SchemaManager.validate_vector_index_dimensions(expected) runs in MemoryClient.connect(). A mismatch between the configured embedder's dimensions and an existing Neo4j vector index raises EmbeddingDimensionMismatchError listing every offending index and pointing at the migration runbook (how-to/migrate-embedding-model.adoc).
  • MCPserve --llm / --embedding CLI flags (plus --llm-api-key, --llm-api-base, --embedding-dimensions) and matching NAM_LLM / NAM_EMBEDDING / NAM_LLM_API_KEY env vars on neo4j-agent-memory mcp serve.
  • LLM-driven session reflections — MemoryObserver(llm_provider=...) uses the configured provider to summarize older messages when the token threshold trips. Falls back to keyword extraction on missing provider or provider error.
  • LLM-driven conversation summaries — ShortTermMemory(default_llm_provider=...) wires the configured provider into get_conversation_summary() so the method works without an explicit summarizer= callable. A module-level _llm_summarizer(provider) helper builds the equivalent callable for user code.
  • Framework pass-through helpers — llm_provider_from_langchain, _pydantic_ai, _llamaindex, _crewai, _openai_agents, _microsoft_agent, _google_adk, and _strands translate a framework-native model object into an LLMProvider. Lets users avoid double-declaring their model.
  • New installation extras — [litellm] (universal fallback) and [instructor] (structured-output power user). [all] now bundles litellm; [full] adds instructor.
  • New tests — tests/unit/llm/ (foundations + contract harness + canned providers), tests/unit/test_legacy_compat.py (deprecation + v0.2 backward compat), tests/unit/test_passthrough.py, tests/unit/test_observer_llm.py, tests/unit/test_short_term_summarizer.py, tests/unit/test_index_validate.py.

Changed

  • MemorySettings.embedding and MemorySettings.llm are now union types. They accept:
    • the legacy EmbeddingConfig / LLMConfig (emits one DeprecationWarning per construction when user-explicit; planned removal in v0.5.0),
    • a provider-string shorthand resolved via from_provider ("openai/text-embedding-3-small", "anthropic/claude-3-5-sonnet-latest"),
    • a fully-constructed Provider instance (the new canonical shape).
      Dict input is still coerced to legacy configs for v0.2 compatibility.
  • MemoryClient.connect() sizes vector indexes from the resolved embedder's dimensions, not from the legacy EmbeddingConfig.dimensions field — works correctly when a Provider instance is configured.
  • LLMEntityExtractor accepts an injected provider: LLMProvider | StructuredExtractor. The legacy model= / api_key= constructor signature continues to work and now constructs the provider internally via from_provider. When the provider also implements StructuredExtractor, the extractor uses complete_structured with a LLMExtractionPayload Pydantic model for native-quality structured outputs.
  • Strands integration routes embedding_provider strings through from_provider instead of mapping to the legacy enum.

Deprecated

  • EmbeddingConfig and LLMConfig as values for MemorySettings.embedding / MemorySettings.llm. Passing either at construction time emits a single DeprecationWarning pointing at the migration guide. Removal planned for v0.5.0. The classes themselves remain importable through v0.5.0 for type-import usage in user code.

Migration

Three patterns are common. Pick the one closest to your existing code.

v0.2.x — legacy explicit configs (still works, one warning per construction):

from neo4j_agent_memory import MemoryClient, MemorySettings
from neo4j_agent_memory.config.settings import (
    EmbeddingConfig, EmbeddingProvider, LLMConfig, LLMProvider,
)

settings = MemorySettings(
    neo4j={"password": "p"},
    embedding=EmbeddingConfig(
        provider=EmbeddingProvider.OPENAI,
        model="text-embedding-3-small",
    ),
    llm=LLMConfig(provider=LLMProvider.OPENAI, model="gpt-4o-mini"),
)

v0.3 — provider-string shorthand (recommended for most users):

from neo4j_agent_memory import MemoryClient, MemorySettings

settings = MemorySettings(
    neo4j={"password": "p"},
    embedding="openai/text-embedding-3-small",
    llm="anthropic/claude-3-5-sonnet-latest",
)

v0.3 — explicit Provider instance (full control, e.g. local vLLM/Ollama):

from neo4j_agent_memory import MemoryClient, MemorySettings
from neo4j_agent_memory.llm.adapters.litellm import LiteLLMProvider

settings = MemorySettings(
    neo4j={"password": "p"},
    embedding="BAAI/bge-small-en-v1.5",
    llm=LiteLLMProvider(
        "ollama/llama3.2",
        api_base="http://localhost:11434",
    ),
)

See docs/.../how-to/migrate-to-v0.3.adoc for the full migration cookbook, including embedding-dimension migration when changing models.

Backward compatibility

  • All v0.2.x example code runs unmodified, emitting exactly one DeprecationWarning per MemoryClient construction. Verified by tests/unit/test_legacy_compat.py.
  • The legacy Embedder Protocol in neo4j_agent_memory.embeddings.base remains; a new internal _ProviderToEmbedderAdapter bridges new Provider instances back to the old API for downstream memory layers that have not migrated.
  • extra="forbid" on MemorySettings is preserved; field-name typos still raise.