Skip to content

Commit

Permalink
feat: Add keepAlive option to OllamaEmbeddings (#415)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmigloz committed May 11, 2024
1 parent 861a2b7 commit 32e1902
Showing 1 changed file with 11 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class OllamaEmbeddings implements Embeddings {
///
/// Main configuration options:
/// - `baseUrl`: the base URL of Ollama API.
/// - [OllamaEmbeddings.keepAlive]
///
/// Advance configuration options:
/// - `headers`: global headers to send with every request. You can use
Expand All @@ -76,6 +77,7 @@ class OllamaEmbeddings implements Embeddings {
/// you need further customization (e.g. to use a Socks5 proxy).
OllamaEmbeddings({
this.model = 'llama2',
this.keepAlive,
final String baseUrl = 'http://localhost:11434/api',
final Map<String, String>? headers,
final Map<String, dynamic>? queryParams,
Expand All @@ -93,6 +95,14 @@ class OllamaEmbeddings implements Embeddings {
/// The embeddings model to use.
final String model;

/// How long (in minutes) to keep the model loaded in memory.
///
/// - If set to a positive duration (e.g. 20), the model will stay loaded for the provided duration.
/// - If set to a negative duration (e.g. -1), the model will stay loaded indefinitely.
/// - If set to 0, the model will be unloaded immediately once finished.
/// - If not set, the model will stay loaded for 5 minutes by default
final int? keepAlive;

@override
Future<List<List<double>>> embedDocuments(
final List<Document> documents,
Expand All @@ -103,6 +113,7 @@ class OllamaEmbeddings implements Embeddings {
request: GenerateEmbeddingRequest(
model: model,
prompt: doc.pageContent,
keepAlive: keepAlive,
),
);
embeddings.add(data.embedding ?? []);
Expand Down

0 comments on commit 32e1902

Please sign in to comment.