Adapters reference

Constructor signatures and notes for every adapter shipped in neo4j_agent_memory.llm.adapters.

All adapters implement one or more of the Protocols in LLM Provider API. Each adapter module imports its underlying SDK lazily — the module itself is importable without the SDK installed.

Overview

Each section below is one adapter constructor, grouped by SDK. Most implement both LLMProvider and StructuredExtractor, or EmbeddingProvider alone; InstructorProvider implements StructuredExtractor only. The Adapter availability section maps each installed extra to the adapters it makes importable.

OpenAIProvider

Module: neo4j_agent_memory.llm.adapters.openai   ·   Extra: [openai]

def OpenAIProvider(
    model: str,
    *,
    api_key: str | None=None,
    api_base: str | None=None,
    organization: str | None=None,
    timeout: float=60.0,
    max_retries: int=3,
    return_raw: bool=False,
    default_headers: dict[str, str] | None=None,
) -> None: ...
  • Implements LLMProvider and StructuredExtractor.

  • Uses OpenAI’s strict-mode response_format={"type": "json_schema", "strict": True} in complete_structured. Falls back to schema_aligned_extract on older models.

  • Strips openai/ prefix from model if present.

OpenAIEmbeddingProvider

Module: neo4j_agent_memory.llm.adapters.openai   ·   Extra: [openai]

def OpenAIEmbeddingProvider(
    model: str='openai/text-embedding-3-small',
    *,
    api_key: str | None=None,
    api_base: str | None=None,
    organization: str | None=None,
    dimensions: int | None=None,
    batch_size: int=100,
    timeout: float=60.0,
    max_retries: int=3,
) -> None: ...
  • Implements EmbeddingProvider.

  • dimensions auto-populated from the defaults table for known models. If user supplies an explicit dimensions smaller than the model’s native size, requests dimension reduction from the API (text-embedding-3-* family).

AnthropicProvider

Module: neo4j_agent_memory.llm.adapters.anthropic   ·   Extra: [anthropic]

def AnthropicProvider(
    model: str,
    *,
    api_key: str | None=None,
    api_base: str | None=None,
    timeout: float=60.0,
    max_retries: int=3,
    return_raw: bool=False,
    cache_system: bool=False,
    default_max_tokens: int=_DEFAULT_MAX_TOKENS,
) -> None: ...
  • Implements LLMProvider and StructuredExtractor.

  • complete_structured uses forced tool use — the model is required to call a single tool whose input_schema is your Pydantic response_model. Falls back to schema_aligned_extract on ValidationError.

  • When cache_system=True, system messages are sent with cache_control={"type": "ephemeral"}.

  • Anthropic requires max_tokens; the adapter defaults to default_max_tokens if the caller does not specify one.

BedrockProvider

Module: neo4j_agent_memory.llm.adapters.bedrock   ·   Extra: [bedrock]

def BedrockProvider(
    model: str,
    *,
    aws_region: str | None=None,
    aws_profile: str | None=None,
    aws_access_key_id: str | None=None,
    aws_secret_access_key: str | None=None,
    timeout: float=60.0,
    return_raw: bool=False,
    default_max_tokens: int=_DEFAULT_MAX_TOKENS,
) -> None: ...
  • Implements LLMProvider and StructuredExtractor.

  • Uses AWS Bedrock Converse API (works for Anthropic/Titan/Llama under one wrapper).

  • Reads credentials via the boto3 chain (env vars, ~/.aws/credentials, IAM role, …).

  • complete_structured uses Converse toolConfig with forced tool choice for Anthropic models; falls back to schema_aligned_extract for Titan/Llama.

BedrockEmbeddingProvider

Module: neo4j_agent_memory.llm.adapters.bedrock   ·   Extra: [bedrock]

def BedrockEmbeddingProvider(
    model: str='bedrock/amazon.titan-embed-text-v2:0',
    *,
    aws_region: str | None=None,
    aws_profile: str | None=None,
    aws_access_key_id: str | None=None,
    aws_secret_access_key: str | None=None,
    dimensions: int | None=None,
    batch_size: int=25,
    normalize: bool=True,
) -> None: ...
  • Implements EmbeddingProvider.

  • Wraps the existing embeddings.bedrock.BedrockEmbedder.

LiteLLMProvider

Module: neo4j_agent_memory.llm.adapters.litellm   ·   Extra: [litellm]

def LiteLLMProvider(
    model: str,
    *,
    api_key: str | None=None,
    api_base: str | None=None,
    aws_region: str | None=None,
    timeout: float=60.0,
    max_retries: int=3,
    return_raw: bool=False,
    **default_kwargs: Any,
) -> None: ...
  • Implements LLMProvider and StructuredExtractor.

  • Fallback through the providers supported by your installed LiteLLM version; model availability and credentials are provider-specific.

  • complete_structured delegates to schema_aligned_extract (LiteLLM has no single structured-output mode that works across all providers).

  • Provider-specific kwargs passed via **default_kwargs are merged into every acompletion call — e.g. aws_region_name="us-east-1" for Bedrock-via-LiteLLM, vertex_project="proj-id" for Vertex AI, api_version="2024-02-15" for Azure.

LiteLLMEmbeddingProvider

Module: neo4j_agent_memory.llm.adapters.litellm   ·   Extra: [litellm]

def LiteLLMEmbeddingProvider(
    model: str,
    *,
    dimensions: int | None=None,
    api_key: str | None=None,
    api_base: str | None=None,
    aws_region: str | None=None,
    timeout: float=60.0,
    max_retries: int=3,
    batch_size: int=100,
    **default_kwargs: Any,
) -> None: ...
  • Implements EmbeddingProvider.

  • dimensions auto-populated for known models; required otherwise.

SentenceTransformersProvider

Module: neo4j_agent_memory.llm.adapters.sentence_transformers   ·   Extra: [sentence-transformers]

def SentenceTransformersProvider(
    model: str='BAAI/bge-small-en-v1.5',
    *,
    device: str | None=None,
    dimensions: int | None=None,
) -> None: ...
  • Implements EmbeddingProvider.

  • Lazy-loads the HuggingFace model on first embed() call.

  • For models in the defaults table, dimensions is populated without loading the model. Unknown models require an explicit dimensions value at construction; otherwise the constructor raises ValueError before model loading. This adapter has no batch_size or normalize_embeddings constructor arguments.

  • device=None auto-detects (CUDA > MPS > CPU).

VertexAIEmbeddingProvider

Module: neo4j_agent_memory.llm.adapters.vertex_ai   ·   Extra: [vertex-ai]

def VertexAIEmbeddingProvider(
    model: str='vertex_ai/text-embedding-004',
    *,
    project_id: str | None=None,
    location: str='us-central1',
    task_type: str='RETRIEVAL_DOCUMENT',
    dimensions: int | None=None,
    batch_size: int=250,
) -> None: ...
  • Implements EmbeddingProvider.

  • Wraps the existing embeddings.vertex_ai.VertexAIEmbedder.

  • task_type is one of RETRIEVAL_QUERY, RETRIEVAL_DOCUMENT, SEMANTIC_SIMILARITY, CLASSIFICATION, CLUSTERING.

  • Pass the SDK-supported model ID explicitly, "vertex_ai/gemini-embedding-001". IDs in the underlying embedder’s retired-model registry raise EmbeddingError when it is constructed. The adapter’s retained default vertex_ai/text-embedding-004 is one such ID, so do not rely on a zero-argument constructor.

  • The underlying embedder truncates output to 768 dimensions by default, so leave dimensions unset (it resolves to 768) or pass dimensions=768. For 1536- or 3072-dimension vectors, construct VertexAIEmbedder(output_dimensionality=…​) directly and pass it as embedder= to MemoryClient — this adapter does not forward output_dimensionality yet.

Vertex AI as an LLM provider routes through LiteLLM — there is no native VertexAIProvider in this SDK.

InstructorProvider

Module: neo4j_agent_memory.llm.adapters.instructor   ·   Extra: [instructor]

def InstructorProvider(model: str, **provider_kwargs: Any) -> None: ...
  • Implements StructuredExtractor only (not LLMProvider).

  • For users already invested in the Instructor library.

  • Calls instructor.from_provider(…​) under the hood.

_DEFAULT_MAX_TOKENS in the Anthropic/Bedrock signatures is 4096. Constructor declarations above show keyword-only arguments and defaults; supply ordinary values when calling them.

Adapter availability

The from_provider factory uses importlib.util.find_spec to detect which adapters are available. Native adapters are preferred when their extra is installed; LiteLLM is the universal fallback. Override with prefer_litellm=True.

Extra Adapters it makes importable

[openai]

OpenAIProvider, OpenAIEmbeddingProvider

[anthropic]

AnthropicProvider

[bedrock]

BedrockProvider, BedrockEmbeddingProvider

[litellm]

LiteLLMProvider, LiteLLMEmbeddingProvider

[sentence-transformers]

SentenceTransformersProvider

[vertex-ai]

VertexAIEmbeddingProvider

[instructor]

InstructorProvider (construct it directly; from_provider does not select it)

See also