embed abstract method

Future<List<LLMEmbedding>> embed({
  1. required String model,
  2. required List<String> messages,
  3. Map<String, dynamic> options = const {},
})

Generates embeddings for the given texts.

Embeddings are vector representations of text that can be used for semantic search, similarity comparison, and other machine learning tasks.

Parameters:

  • model - The embedding model to use (e.g., 'text-embedding-3-small', 'nomic-embed-text'). Must be a model that supports embeddings.
  • messages - The texts to embed. Each string will be converted to an embedding vector. Must not be empty.
  • options - Additional model-specific options. Format depends on the backend:
    • Ollama: Options are passed directly to the API
    • ChatGPT: Currently unused (OpenAI API doesn't support additional options)
    • llama.cpp: Currently unused

Returns: A Future<List<LLMEmbedding>> containing one embedding per input message. Each embedding contains:

  • embedding - The embedding vector as a list of doubles
  • model - The model that generated the embedding
  • promptEvalCount - Number of tokens in the input text

Example:

final embeddings = await repo.embed(
  model: 'text-embedding-3-small',
  messages: ['Hello world', 'Goodbye world'],
);

print('Embedding dimension: ${embeddings[0].embedding.length}');
print('First embedding: ${embeddings[0].embedding.take(5).toList()}');

Throws:

Implementation

Future<List<LLMEmbedding>> embed({
  required String model,
  required List<String> messages,
  Map<String, dynamic> options = const {},
});