LLMs and Embedders

This page presents the abstract interfaces used to plug LLMs and embedders into Oracle Agent Memory.

LLM Interface

class oracleagentmemory.apis.llms.ILlm

Bases: ABC

Abstract interface for LLM invocation.

method generate (abstract)

Generate a response from an LLM synchronously.

method generate_async (abstract, async)

Asynchronously generate a response from an LLM.

LLM Responses

class oracleagentmemory.apis.llms.LlmResponse

Bases: object

A small normalized response returned by ILlm.

text

The primary generated text content.

Embedder Interface

class oracleagentmemory.apis.IEmbedder

Bases: ABC

Abstract interface for text embedders.

method embed (abstract)

Embed a batch of texts into a 2D float32 NumPy array.

method embed_async (abstract, async)

Embed a batch of texts into a 2D float32 NumPy array.

property embedding_dimension

Subclasses may override this property when the embedding width is known from configuration or provider metadata. The default implementation probes embed() once and caches the result size.

property max_input_tokens

Subclasses may override this property when the model’s input budget is known from configuration or provider metadata. The default implementation validates a probe sized to an estimated 512 input tokens once and caches 512 as a conservative fallback. It does not run a model tokenizer locally, so callers should set max_input_tokens manually when the model’s actual input budget is known.

LiteLLM Adapters

class oracleagentmemory.core.llms.LlmApiType

Bases: str, Enum

Supported OpenAI-compatible API families for Llm.

CHAT_COMPLETIONS = ‘chat_completions’

RESPONSES = ‘responses’

class oracleagentmemory.core.llms.Llm

Bases: ILlm

Adapter for generating model responses.

Create an LLM adapter.

Examples

OCI Generative AI models use LiteLLM’s "oci/..." model identifiers. A common setup is to pass OCI API key authentication details from the standard OCI config file through LiteLLM-specific keyword arguments. The OCI Python SDK is not installed by this package; applications that already depend on it may alternatively pass an oci_signer object.

import configparser
from pathlib import Path
parser = configparser.RawConfigParser()
parser.read(Path("~/.oci/config").expanduser())
cfg = parser["DEFAULT"]
key_file = Path(cfg["key_file"]).expanduser()
oci_llm = Llm(
    model="oci/openai.gpt-oss-120b",
    oci_compartment_id="ocid1.compartment.oc1..example",
    oci_region=cfg.get("region", "us-chicago-1"),
    oci_user=cfg["user"],
    oci_fingerprint=cfg["fingerprint"],
    oci_tenancy=cfg["tenancy"],
    oci_key_file=str(key_file),
)
oci_llm.generate("Reply with OK.")

OpenAI-hosted models use LiteLLM model identifiers such as "openai/gpt-5.1" and an OpenAI API key. Chat Completions is the default API family.

openai_llm = Llm(
    model="openai/gpt-5.1",
    api_key="sk-example",
    temperature=0,
    max_tokens=128,
)
openai_llm.model
'openai/gpt-5.1'
openai_llm.generate("Reply with OK.")

Use api_type=LlmApiType.RESPONSES when the target model should be called through the OpenAI Responses API instead of Chat Completions.

responses_llm = Llm(
    model="openai/gpt-5.4",
    api_key="sk-example",
    api_type=LlmApiType.RESPONSES,
    reasoning_effort="high",
    stream=True,
)
responses_llm.model
'openai/gpt-5.4'

Self-hosted OpenAI-compatible servers, including vLLM, are called with an "openai/..." model identifier plus the server’s /v1 base URL. Pass a nominal api_key such as "none" when the endpoint does not enforce authentication.

vllm_llm = Llm(
    model="openai/openai/gpt-oss-120b",
    api_base="http://localhost:8000/v1",
    api_key="none",
    stream=True,
)
vllm_llm.model
'openai/openai/gpt-oss-120b'
vllm_llm.generate("Reply with OK.")

method generate

Generate a response.

method generate_async (async)

Asynchronously generate a response.

class oracleagentmemory.core.embedders.Embedder

Bases: IEmbedder

Provider-backed embedder.

Create a provider-backed embedder.

Examples

OCI Generative AI embedding models use "oci/..." model identifiers. A common setup is to pass OCI API key authentication details from the standard OCI config file through LiteLLM-specific keyword arguments. The OCI Python SDK is not installed by this package; applications that already depend on it may alternatively pass an oci_signer object.

import configparser
from pathlib import Path
parser = configparser.RawConfigParser()
parser.read(Path("~/.oci/config").expanduser())
cfg = parser["DEFAULT"]
key_file = Path(cfg["key_file"]).expanduser()
oci_embedder = Embedder(
    model="oci/cohere.embed-english-v3.0",
    oci_compartment_id="ocid1.compartment.oc1..example",
    oci_region=cfg.get("region", "us-chicago-1"),
    oci_user=cfg["user"],
    oci_fingerprint=cfg["fingerprint"],
    oci_tenancy=cfg["tenancy"],
    oci_key_file=str(key_file),
)
oci_embedder.embed(["hello world"])

OpenAI-hosted embedding models use identifiers such as "openai/text-embedding-3-small" with an OpenAI API key.

openai_embedder = Embedder(
    model="openai/text-embedding-3-small",
    api_key="sk-example",
    truncate_prompt_tokens=8192,
)
openai_embedder.model
'openai/text-embedding-3-small'
openai_embedder.embed(["hello world"])

Self-hosted OpenAI-compatible embedding servers, including vLLM, use the "hosted_vllm/..." provider prefix with the server’s /v1 base URL.

vllm_embedder = Embedder(
    model="hosted_vllm/sentence-transformers/all-MiniLM-L6-v2",
    api_base="http://localhost:8000/v1",
)
vllm_embedder.model
'hosted_vllm/sentence-transformers/all-MiniLM-L6-v2'
vllm_embedder.embed(["hello world"])

method embed

Embed a batch of texts using the configured provider.

method embed_async (async)

Asynchronously embed a batch of texts using the configured provider.

property embedding_dimension

Notes

A constructor-provided value is returned without contacting the provider. Otherwise the property probes once and caches the result.

property max_input_tokens

Notes

A constructor-provided value is returned without contacting the provider. Otherwise, the property validates a provider probe sized to an estimated 512 input tokens and caches 512 as a conservative fallback. It does not run a model tokenizer locally, so set max_input_tokens manually from the model’s documented input budget when precision matters.

Oracle DB Embedders

class oracleagentmemory.core.embedders.OracleDBEmbedder

Bases: IEmbedder

Embed text by invoking Oracle Database embedding SQL.

This embedder keeps the package’s existing embedder contract intact while delegating embedding generation to the database over SQL. Direct embedding prefers VECTOR_EMBEDDING for database-resident model configurations and falls back to DBMS_VECTOR_CHAIN.UTL_TO_EMBEDDING when the vectorizer configuration needs the JSON provider-parameter surface.

Create an embedder backed by Oracle Database SQL execution.

Examples

Use an Oracle connection pool and a DB-resident embedding model:

import oracledb
pool = oracledb.create_pool(
    user="scott",
    password="tiger",
    dsn="dbhost.example.com/orclpdb",
)
embedder = OracleDBEmbedder(
    connection=pool,
    model="DOC_MODEL",
    embedding_dimension=768,
)
embedder.embed(["hello world"])

Schema-qualified model names can be used when the connected schema has privileges on a model owned by another schema:

shared_embedder = OracleDBEmbedder(
    connection=pool,
    model="MY_OTHER_SCHEMA.MY_ONNX_MODEL",
    embedding_dimension=768,
)
shared_embedder.embed(["hello world"])

Query-specific prefixes can be configured without changing the store API:

embedder = OracleDBEmbedder(
    connection=pool,
    model="DOC_MODEL",
    query_prefix="search_document: ",
)
embedder.embed(["pizza"], is_query=True)

method embed

Embed a batch of texts by executing SQL in Oracle Database.

Examples

embedder = OracleDBEmbedder(
    connection=pool,
    model="DOC_MODEL",
)
matrix = embedder.embed(["alpha", "beta"])
matrix.shape[0]
2

method embed_async (async)

Asynchronously embed a batch of texts using Oracle Database SQL.

Examples

embedder = OracleDBEmbedder(
    connection=pool,
    model="DOC_MODEL",
)
matrix = await embedder.embed_async(["hello"])
matrix.shape
(1, 384)

property embedding_dimension

Notes

A constructor-provided value is returned without contacting the database model. Otherwise the property probes once and caches the result for future accesses.

Examples

embedder = OracleDBEmbedder(
    connection=pool,
    model="DOC_MODEL",
    embedding_dimension=768,
)
embedder.embedding_dimension
768

method get_vectorizer_config_json

Return Oracle vectorizer preference JSON for this DB model.

The same model configuration is used by direct embedding and by managed hybrid indexes. Direct embedding uses it to decide whether VECTOR_EMBEDDING can represent the configured database model or whether DBMS_VECTOR_CHAIN.UTL_TO_EMBEDDING is needed for provider JSON. Hybrid indexing passes it to DBMS_VECTOR_CHAIN.CREATE_PREFERENCE and then Oracle’s vectorizer pipeline owns embedding work for that index.

Examples

embedder = OracleDBEmbedder(
    connection=pool,
    model="DOC_MODEL",
    embedding_dimension=768,
)
embedder.get_vectorizer_config_json()
'{"model":"DOC_MODEL"}'
custom_embedder = OracleDBEmbedder(
    connection=pool,
    model="DOC_MODEL",
    input_name="TEXT",
    embedding_dimension=768,
)
custom_embedder.get_vectorizer_config_json()
'{"model":"DOC_MODEL","input_name":"TEXT"}'
shared_embedder = OracleDBEmbedder(
    connection=pool,
    model="MY_OTHER_SCHEMA.MY_ONNX_MODEL",
    embedding_dimension=768,
)
shared_embedder.get_vectorizer_config_json()
'{"model":"MY_OTHER_SCHEMA.MY_ONNX_MODEL"}'

property max_input_tokens

Notes

A constructor-provided value is returned without contacting the database model. Otherwise, the property validates a database-model probe sized to an estimated 512 input tokens and caches 512 as a conservative fallback. It does not run a model tokenizer locally, so set max_input_tokens manually from the model’s documented input budget when precision matters.

Examples

embedder = OracleDBEmbedder(
    connection=pool,
    model="DOC_MODEL",
    max_input_tokens=2048,
)
embedder.max_input_tokens
2048