Repository navigation
v0.4.0
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 everyclient.short_term,client.long_term,client.reasoning, andclient.querycall to the hosted REST API athttps://memory.neo4jlabs.com/v1(default endpoint, overridable). SPEC tier conformance targets Bronze, Silver, Gold, and Platinum. -
neo4j_agent_memory.namspackage — new public surface:NamsConfig— endpoint, api_key (SecretStr), timeout, retries, headers,validate_on_connect,transport_mode.AuthProviderProtocol +StaticApiKeyAuth(Authorization: Bearer {api_key}).HttpTransport— httpx-based async client with retry policy (429 honorsRetry-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 byMemoryClient.connect()whenbackend == "nams".
-
neo4j_agent_memory.core.protocols— three new@runtime_checkableProtocols (ShortTermProtocol,LongTermProtocol,ReasoningProtocol) plusCypherQueryProtocol. ExistingShortTermMemory/LongTermMemory/ReasoningMemorybolt classes structurally satisfy them; newNamsShortTermMemory/NamsLongTermMemory/NamsReasoningMemoryimplement them over HTTP. -
client.query.cypher(query, params)— unified read-only Cypher accessor. Works on both backends. On bolt, forwards toNeo4jClient.execute_read; on NAMS, forwards toPOST /v1/query(Platinum). Read-only enforcement uses a sharedis_read_only_queryvalidator. -
Platinum-tier methods on
client.long_termandclient.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
NotSupportedErrorat call time. -
New exceptions in
neo4j_agent_memory.core.exceptions:TransportError(ConnectionError)— HTTP transport failures (5xx, network).AuthenticationError(MemoryError)— 401/403.NotSupportedError(MemoryError)— structured withbackend,method,workaround.RateLimitError(MemoryError)— 429, carriesretry_after.ValidationError(MemoryError)— 400, carriesdetails.
Existing
except ConnectionErrorblocks still catch transport failures (sinceTransportErroris 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@toolfunctions for NAMS Platinum operations. Auto-readsMEMORY_API_KEY/MEMORY_ENDPOINTfrom 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 underlyingMemoryClientusesbackend == "nams". register_tools(mcp, *, profile, register_platinum)parameter.
- Four new Platinum tools (
-
CLI —
neo4j-agent-memory mcp serveaccepts new flags:--backend {bolt,nams}(env:NAM_BACKEND)--api-key(env:MEMORY_API_KEY)--endpoint(env:MEMORY_ENDPOINT)
-
Environment variables —
MEMORY_API_KEYandMEMORY_ENDPOINTare recognized byMemorySettings. WhenMEMORY_API_KEYis set andbackendis 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; fullNotSupportedErrortable.tutorials/nams-quickstart.adoc— 5-minute walkthrough.
-
Examples:
examples/nams-quickstart/— minimal end-to-end NAMS usage.examples/nams-langchain/— LangChainConversationChainbacked 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 onMemorySettings.backend. When unset, NAMS ifMEMORY_API_KEYis in the environment, otherwise bolt.client.graphraisesNotSupportedErroron NAMS — useclient.query.cypher()for portable read-only queries. On bolt, returns a deprecation proxy that emits a one-timeDeprecationWarningonexecute_readcalls;execute_writecontinues to work without deprecation.client.users,client.buffered,client.consolidation— on NAMS, accessors return a_NamsUnsupportedsentinel that raisesNotSupportedErrorwith workaround hints on any method call.client.schema— on NAMS, returns a_NamsUnsupportedsentinel (adopt_existing_graphand other schema operations are server-managed by NAMS).client.get_stats,client.get_graph,client.get_locations— raiseNotSupportedErroron NAMS (rely on bolt-specific Cypher; useclient.query.cypher()with a custom query).- MCP
graph_querytool,_get_entity_neighborshelper,memory://graph/statsresource — migrated fromclient.graph.execute_readtoclient.query.cypher. Now portable across both backends. - Strands
context_graph_toolsinternal Cypher, AgentCoreHybridMemoryProvider._enrich_with_relationships, andEvalMemory._eval_audit— same migration. All work on both backends.
Deprecated
client.graph.execute_read— useclient.query.cypherfor portable read-only queries. Emits one-timeDeprecationWarningper 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_xxxxxMemoryClient()now talks to NAMS. Methods that don't apply (geocoding, enrichment, deduplication knobs) emit a singleUserWarningatconnect()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.llmpackage — new public surface for the Provider Protocol. Three@runtime_checkableProtocols: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 viacache_system=True),BedrockProvider,BedrockEmbeddingProvider,SentenceTransformersProvider,VertexAIEmbeddingProvider,InstructorProvider. - Universal adapter —
LiteLLMProviderandLiteLLMEmbeddingProvidercover 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 withprefer_litellm=True. Unknown-extra errors include an actionable install hint.- Vector index dimension validation —
SchemaManager.validate_vector_index_dimensions(expected)runs inMemoryClient.connect(). A mismatch between the configured embedder'sdimensionsand an existing Neo4j vector index raisesEmbeddingDimensionMismatchErrorlisting every offending index and pointing at the migration runbook (how-to/migrate-embedding-model.adoc). MCPserve --llm/--embeddingCLI flags (plus--llm-api-key,--llm-api-base,--embedding-dimensions) and matchingNAM_LLM/NAM_EMBEDDING/NAM_LLM_API_KEYenv vars onneo4j-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 intoget_conversation_summary()so the method works without an explicitsummarizer=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_strandstranslate a framework-native model object into anLLMProvider. Lets users avoid double-declaring their model. - New installation extras —
[litellm](universal fallback) and[instructor](structured-output power user).[all]now bundleslitellm;[full]addsinstructor. - 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.embeddingandMemorySettings.llmare now union types. They accept:- the legacy
EmbeddingConfig/LLMConfig(emits oneDeprecationWarningper 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.
- the legacy
MemoryClient.connect()sizes vector indexes from the resolved embedder'sdimensions, not from the legacyEmbeddingConfig.dimensionsfield — works correctly when a Provider instance is configured.LLMEntityExtractoraccepts an injectedprovider: LLMProvider | StructuredExtractor. The legacymodel=/api_key=constructor signature continues to work and now constructs the provider internally viafrom_provider. When the provider also implementsStructuredExtractor, the extractor usescomplete_structuredwith aLLMExtractionPayloadPydantic model for native-quality structured outputs.- Strands integration routes
embedding_providerstrings throughfrom_providerinstead of mapping to the legacy enum.
Deprecated
EmbeddingConfigandLLMConfigas values forMemorySettings.embedding/MemorySettings.llm. Passing either at construction time emits a singleDeprecationWarningpointing 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
DeprecationWarningperMemoryClientconstruction. Verified bytests/unit/test_legacy_compat.py. - The legacy
EmbedderProtocol inneo4j_agent_memory.embeddings.baseremains; a new internal_ProviderToEmbedderAdapterbridges new Provider instances back to the old API for downstream memory layers that have not migrated. extra="forbid"onMemorySettingsis preserved; field-name typos still raise.