text2vec-ollama
Overview
v1.25
The text2vec-ollama
module enables Weaviate to obtain vectors using Ollama. Ollama is a tool for simplifying the process of running embedding and large language models, such as GPT-3, on your own hardware. This module allows you to use Ollama to generate embeddings for your data in Weaviate.
Key notes:
- This module is not available on Weaviate Cloud (WCD).
- This module assumes an Ollama endpoint is available to you (e.g. by running a local Ollama instance on your own device).
- Your Weaviate instance must be able to access the Ollama endpoint. If you are running Weaviate via Docker, you can specify the Ollama endpoint using
host.docker.internal
to access the host machine from within the container. - Enabling this module will enable the
nearText
search operator. - The default model is
nomic-embed-text
.- The specified model must be available in the Ollama instance you are using.
Weaviate instance configuration
This module is not available on Weaviate Cloud.
Docker Compose file
To use text2vec-ollama
, you must enable it in your Docker Compose file (docker-compose.yml
). You can do so manually, or create one using the Weaviate configuration tool.
Parameters
ENABLE_MODULES
(Required): The modules to enable. Includetext2vec-ollama
to enable the module.DEFAULT_VECTORIZER_MODULE
(Optional): The default vectorizer module. You can set this totext2vec-ollama
to make it the default for all collections.
Example
This configuration enables text2vec-ollama
, sets it as the default vectorizer, and sets the API keys.
---
version: '3.4'
services:
weaviate:
command:
- --host
- 0.0.0.0
- --port
- '8080'
- --scheme
- http
image: cr.weaviate.io/semitechnologies/weaviate:1.25.1
ports:
- 8080:8080
- 50051:50051
restart: on-failure:0
environment:
QUERY_DEFAULTS_LIMIT: 25
AUTHENTICATION_ANONYMOUS_ACCESS_ENABLED: 'true'
PERSISTENCE_DATA_PATH: '/var/lib/weaviate'
DEFAULT_VECTORIZER_MODULE: 'text2vec-ollama'
ENABLE_MODULES: 'text2vec-ollama'
CLUSTER_HOSTNAME: 'node1'
...
Collection configuration
You can configure how the module will behave in each collection through the Weaviate schema.
Configurable parameters for the text2vec-ollama
module are:
apiEndpoint
- the URL of the Ollama endpoint.model
- the model to use for vectorization.
Ollama endpoint
Optionally, you can provide the apiEndpoint
parameter as shown below to specify the URL of the Ollama endpoint.
If you are running Weaviate via Docker, with a local Ollama instance, specify host.docker.internal:<ollama-port>
to access the host machine from within the container, where <ollama-port>
is the port on which Ollama is running (default: 11434
).
Example
The following example configures the Article
collection, with:
- Vectorizer set to
text2vec-ollama
, - The Ollama endpoint set to
host.docker.internal
, and - The model set to
snowflake-arctic-embed
.
{
"classes": [
{
"class": "Article",
"description": "A collection called article",
"vectorizer": "text2vec-ollama",
"moduleConfig": {
"text2vec-ollama": {
"apiEndpoint": "http://host.docker.internal:11434",
"model": "snowflake-arctic-embed"
}
},
}
]
}
Vectorization settings
You can set vectorizer behavior using the moduleConfig
section under each collection and property:
Collection-level
vectorizer
- what module to use to vectorize the data.vectorizeClassName
– whether to vectorize the collection name. Default:true
.apiEndpoint
– the URL of the Ollama endpoint. Default:http://localhost:11434
.model
– the model to use for vectorization. Default:nomic-embed-text
.
Property-level
skip
– whether to skip vectorizing the property altogether. Default:false
vectorizePropertyName
– whether to vectorize the property name. Default:false
Example
{
"classes": [
{
"class": "Article",
"description": "A class called article",
"vectorizer": "text2vec-ollama",
"moduleConfig": {
"text2vec-ollama": {
"vectorizeClassName": false,
"apiEndpoint": "http://host.docker.internal:11434",
"model": "snowflake-arctic-embed"
}
},
"properties": [
{
"name": "content",
"dataType": ["text"],
"description": "Content that will be vectorized",
"moduleConfig": {
"text2vec-ollama": {
"skip": false,
"vectorizePropertyName": false
}
}
}
]
}
]
}
Additional information
Available models
Please refer to the Ollama documentation for a list of available models. This list includes both large language models and embedding models; look for the word embed
in the name or description to identify embedding models.
Download the desired model with ollama pull <model-name>
.
Ollama documentation
- Ollama models
- Note: Look for the word
embed
in the name or description to identify embedding models.
- Note: Look for the word
- Ollama repository
- How to change the host and port of the Ollama server
Usage example
This is an example of a nearText
query with text2vec-ollama
.
- Python Client v4
- Python Client v3
- JavaScript/TypeScript
- Go
- Java
- Curl
- GraphQL
import weaviate
import weaviate.classes as wvc
from weaviate.collections.classes.grpc import Move
import os
client = weaviate.connect_to_local()
try:
publications = client.collections.get("Publication")
response = publications.query.near_text(
query="fashion",
distance=0.6,
move_to=Move(force=0.85, concepts="haute couture"),
move_away=Move(force=0.45, concepts="finance"),
return_metadata=wvc.query.MetadataQuery(distance=True),
limit=2
)
for o in response.objects:
print(o.properties)
print(o.metadata)
finally:
client.close()
import weaviate
client = weaviate.Client("http://localhost:8080")
nearText = {
"concepts": ["fashion"],
"distance": 0.6, # prior to v1.14 use "certainty" instead of "distance"
"moveAwayFrom": {
"concepts": ["finance"],
"force": 0.45
},
"moveTo": {
"concepts": ["haute couture"],
"force": 0.85
}
}
result = (
client.query
.get("Publication", "name")
.with_additional(["certainty OR distance"]) # note that certainty is only supported if distance==cosine
.with_near_text(nearText)
.do()
)
print(result)
import weaviate from 'weaviate-ts-client';
const client = weaviate.client({
scheme: 'http',
host: 'localhost:8080',
});
const response = await client.graphql
.get()
.withClassName('Publication')
.withFields('name _additional{certainty distance}') // note that certainty is only supported if distance==cosine
.withNearText({
concepts: ['fashion'],
distance: 0.6, // prior to v1.14 use certainty instead of distance
moveAwayFrom: {
concepts: ['finance'],
force: 0.45,
},
moveTo: {
concepts: ['haute couture'],
force: 0.85,
},
})
.do();
console.log(response);
package main
import (
"context"
"fmt"
"github.com/weaviate/weaviate-go-client/v4/weaviate"
"github.com/weaviate/weaviate-go-client/v4/weaviate/graphql"
)
func main() {
cfg := weaviate.Config{
Host: "localhost:8080",
Scheme: "http",
}
client, err := weaviate.NewClient(cfg)
if err != nil {
panic(err)
}
className := "Publication"
name := graphql.Field{Name: "name"}
_additional := graphql.Field{
Name: "_additional", Fields: []graphql.Field{
{Name: "certainty"}, // only supported if distance==cosine
{Name: "distance"}, // always supported
},
}
concepts := []string{"fashion"}
distance := float32(0.6)
moveAwayFrom := &graphql.MoveParameters{
Concepts: []string{"finance"},
Force: 0.45,
}
moveTo := &graphql.MoveParameters{
Concepts: []string{"haute couture"},
Force: 0.85,
}
nearText := client.GraphQL().NearTextArgBuilder().
WithConcepts(concepts).
WithDistance(distance). // use WithCertainty(certainty) prior to v1.14
WithMoveTo(moveTo).
WithMoveAwayFrom(moveAwayFrom)
ctx := context.Background()
result, err := client.GraphQL().Get().
WithClassName(className).
WithFields(name, _additional).
WithNearText(nearText).
Do(ctx)
if err != nil {
panic(err)
}
fmt.Printf("%v", result)
}
package io.weaviate;
import io.weaviate.client.Config;
import io.weaviate.client.WeaviateClient;
import io.weaviate.client.base.Result;
import io.weaviate.client.v1.graphql.model.GraphQLResponse;
import io.weaviate.client.v1.graphql.query.argument.NearTextArgument;
import io.weaviate.client.v1.graphql.query.argument.NearTextMoveParameters;
import io.weaviate.client.v1.graphql.query.fields.Field;
public class App {
public static void main(String[] args) {
Config config = new Config("http", "localhost:8080");
WeaviateClient client = new WeaviateClient(config);
NearTextMoveParameters moveTo = NearTextMoveParameters.builder()
.concepts(new String[]{ "haute couture" }).force(0.85f).build();
NearTextMoveParameters moveAway = NearTextMoveParameters.builder()
.concepts(new String[]{ "finance" }).force(0.45f)
.build();
NearTextArgument nearText = client.graphQL().arguments().nearTextArgBuilder()
.concepts(new String[]{ "fashion" })
.distance(0.6f) // use .certainty(0.7f) prior to v1.14
.moveTo(moveTo)
.moveAwayFrom(moveAway)
.build();
Field name = Field.builder().name("name").build();
Field _additional = Field.builder()
.name("_additional")
.fields(new Field[]{
Field.builder().name("certainty").build(), // only supported if distance==cosine
Field.builder().name("distance").build(), // always supported
}).build();
Result<GraphQLResponse> result = client.graphQL().get()
.withClassName("Publication")
.withFields(name, _additional)
.withNearText(nearText)
.run();
if (result.hasErrors()) {
System.out.println(result.getError());
return;
}
System.out.println(result.getResult());
}
}
# Note: Under nearText, use `certainty` instead of distance prior to v1.14
# Under _additional, `certainty` is only supported if distance==cosine, but `distance` is always supported
echo '{
"query": "{
Get {
Publication(
nearText: {
concepts: [\"fashion\"],
distance: 0.6,
moveAwayFrom: {
concepts: [\"finance\"],
force: 0.45
},
moveTo: {
concepts: [\"haute couture\"],
force: 0.85
}
}
) {
name
_additional {
certainty
distance
}
}
}
}"
}' | curl \
-X POST \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer learn-weaviate' \
-H "X-OpenAI-Api-Key: $OPENAI_API_KEY" \
-d @- \
https://edu-demo.weaviate.network/v1/graphql
{
Get{
Publication(
nearText: {
concepts: ["fashion"],
distance: 0.6 # prior to v1.14 use "certainty" instead of "distance"
moveAwayFrom: {
concepts: ["finance"],
force: 0.45
},
moveTo: {
concepts: ["haute couture"],
force: 0.85
}
}
){
name
_additional {
certainty # only supported if distance==cosine.
distance # always supported
}
}
}
}
Model license(s)
The text2vec-ollama
module uses various models though Ollama. Please refer to the respective documentation for Ollama and the specific model for more information on their respective licenses.
It is your responsibility to evaluate whether the terms of its license(s), if any, are appropriate for your intended use.
If you have any questions or feedback, let us know in the user forum.