Skip to main content

Interface: IEmbeddingManager

Defined in: packages/agentos/src/rag/IEmbeddingManager.ts:175

IEmbeddingManager

Description

Defines the contract for managing and utilizing embedding models. Implementations of this interface are responsible for generating vector embeddings from text, handling different model providers, and potentially managing caching and model selection strategies.

Methods

checkHealth()

checkHealth(): Promise<{ details?: any; isHealthy: boolean; }>

Defined in: packages/agentos/src/rag/IEmbeddingManager.ts:286

Checks the operational health of the EmbeddingManager. This may involve verifying its initialization status and, potentially, the health of its connections to default or critical LLM providers.

Returns

Promise<{ details?: any; isHealthy: boolean; }>

A promise that resolves with an object indicating health status and optionally providing more details (e.g., status of providers, cache).

Async

Example

const health = await embeddingManager.checkHealth();
if (health.isHealthy) {
console.log("EmbeddingManager is healthy.");
} else {
console.error("EmbeddingManager health check failed:", health.details);
}

generateEmbeddings()

generateEmbeddings(request): Promise<EmbeddingResponse>

Defined in: packages/agentos/src/rag/IEmbeddingManager.ts:225

Generates embeddings for the provided text(s) using an appropriate model. This method handles model selection (if not explicitly specified in the request), interaction with the LLM provider, and caching (if enabled).

Parameters

request

EmbeddingRequest

The request object containing the text(s) to embed and any relevant options.

Returns

Promise<EmbeddingResponse>

A promise that resolves with the generated embeddings, usage details, and information about the model used.

Async

Throws

If the embedding generation process fails critically (e.g., provider unavailable, authentication error, invalid request parameters not caught by initial validation). A GMIError with a code like 'PROVIDER_ERROR', 'REQUEST_FAILED', or 'NOT_INITIALIZED' is preferred. For batch requests, individual text failures might be reported in EmbeddingResponse.errors instead of throwing.

Example

const response = await embeddingManager.generateEmbeddings({
texts: ["What is the capital of France?", "Explain quantum computing."],
userId: "user-xyz"
});
console.log(response.embeddings);

getEmbeddingDimension()

getEmbeddingDimension(modelId?): Promise<number>

Defined in: packages/agentos/src/rag/IEmbeddingManager.ts:266

Gets the embedding dimension for a specific model, or the default system dimension. This is crucial for configuring vector stores and other components that need to know the size of the embedding vectors.

Parameters

modelId?

string

Optional: The ID of the model. If omitted, tries to return the dimension of the default model, or a system-wide default embedding dimension if configured.

Returns

Promise<number>

A promise that resolves with the embedding dimension.

Async

Throws

If the dimension cannot be determined (e.g., model not found and no default dimension configured). A GMIError with code 'CONFIG_ERROR' or 'NOT_FOUND' is preferred.

Example

const dimension = await embeddingManager.getEmbeddingDimension("text-embedding-3-small");
console.log(`Embeddings will have ${dimension} dimensions.`);

getEmbeddingModelInfo()

getEmbeddingModelInfo(modelId?): Promise<EmbeddingModelConfig | undefined>

Defined in: packages/agentos/src/rag/IEmbeddingManager.ts:245

Retrieves configuration information for a specific embedding model. If no modelId is provided, it typically returns information for the default configured embedding model.

Parameters

modelId?

string

Optional: The ID of the model to get information for. If omitted, the default model's info is returned.

Returns

Promise<EmbeddingModelConfig | undefined>

A promise that resolves with the model's configuration object, or undefined if the model is not found.

Async

Throws

If the manager is not initialized.

Example

const modelInfo = await embeddingManager.getEmbeddingModelInfo("text-embedding-ada-002");
if (modelInfo) {
console.log(`Model Dimensions: ${modelInfo.dimension}`);
}

initialize()

initialize(config, providerManager): Promise<void>

Defined in: packages/agentos/src/rag/IEmbeddingManager.ts:197

Initializes the EmbeddingManager with its configuration and necessary dependencies. This method must be called before any other operations can be performed. It sets up available embedding models, caching, and selection strategies.

Parameters

config

EmbeddingManagerConfig

The configuration object for the EmbeddingManager. This includes details about available models, caching, and default settings.

providerManager

AIModelProviderManager

An instance of AIModelProviderManager, used to interact with the actual LLM providers that generate embeddings.

Returns

Promise<void>

A promise that resolves when initialization is complete.

Async

Throws

If initialization fails due to invalid configuration, inability to set up providers, or other critical errors. A GMIError with a code like 'CONFIG_ERROR' or 'INITIALIZATION_FAILED' is preferred.

Example

const manager = new EmbeddingManager();
await manager.initialize(embeddingManagerConfig, aiModelProviderManager);

shutdown()?

optional shutdown(): Promise<void>

Defined in: packages/agentos/src/rag/IEmbeddingManager.ts:298

Gracefully shuts down the EmbeddingManager, releasing any resources it holds. This could include clearing caches, closing persistent connections if any were managed directly (though typically provider connections are managed by AIModelProviderManager).

Returns

Promise<void>

A promise that resolves when shutdown is complete.

Async

Example

await embeddingManager.shutdown();