Connection String to Ollama



Define the connection string - from the Studio

connection string to ollama

Define a connection string to Ollama

  1. Name
    Enter a name for this connection string.

  2. Identifier (optional)
    Learn more about the identifier in the connection string identifier section.

  3. Connector
    Select Ollama from the dropdown menu.

  4. Model
    Specify the Ollama text embedding model to use.

  5. URI
    Enter the Ollama API URI.

  6. Max concurrent query batches: (optional)

    • When making vector search queries, the content of the search terms must also be converted to embeddings to compare them against the stored vectors. Requests to generate such query embeddings via the AI provider are sent in batches.
    • This parameter defines the maximum number of these batches that can be processed concurrently.
      You can set a default value using the Ai.Embeddings.MaxConcurrentBatches configuration key.
  7. Click Test Connection to confirm the connection string is set up correctly.

  8. Click Save to store the connection string or Cancel to discard changes.

Define the connection string - from the Client API

using (var store = new DocumentStore())
{
    // Define the connection string to Ollama
    var connectionString = new AiConnectionString
    {
        // Connection string name & identifier
        Name = "ConnectionStringToOllama", 
        Identifier = "identifier-to-the-connection-string", // optional
        
        // Ollama connection settings
        OllamaSettings = new OllamaSettings(
            uri: "http://localhost:11434/",
            model: "mxbai-embed-large")
    };
    
    // Optionally, override the default maximum number of query embedding batches
    // that can be processed concurrently 
    connectionString.OllamaSettings.EmbeddingsMaxConcurrentBatches = 10;
    
    // Deploy the connection string to the server
    var operation = new PutConnectionStringOperation<AiConnectionString>(connectionString);
    var putConnectionStringResult = store.Maintenance.Send(operation);
}

Syntax

public class AiConnectionString
{
    public string Name { get; set; }
    public string Identifier { get; set; }
    public OllamaSettings OllamaSettings { get; set; }
}

public class OllamaSettings : AbstractAiSettings
{
    public string Uri { get; set; }
    public string Model { get; set; }
}

public class AbstractAiSettings
{
    public int? EmbeddingsMaxConcurrentBatches { get; set; }
}