From df4d36ba3f16cd5346a560610534483fac6f7f52 Mon Sep 17 00:00:00 2001 From: Cameron McCord Date: Tue, 2 Jul 2024 09:41:31 -0400 Subject: [PATCH 1/2] Allow using Ollama as a vectorizer --- README.md | 51 ++++++++++++++++++++++++++++++++++++++---- lib/weaviate/client.rb | 1 + 2 files changed, 48 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 28cc4d7..1344565 100644 --- a/README.md +++ b/README.md @@ -63,7 +63,7 @@ client.schema.create( "name": "category" } ], - # Possible values: 'text2vec-cohere', 'text2vec-openai', 'text2vec-huggingface', 'text2vec-transformers', 'text2vec-contextionary', 'img2vec-neural', 'multi2vec-clip', 'ref2vec-centroid' + # Possible values: 'text2vec-cohere', 'text2vec-ollama', 'text2vec-openai', 'text2vec-huggingface', 'text2vec-transformers', 'text2vec-contextionary', 'img2vec-neural', 'multi2vec-clip', 'ref2vec-centroid' vectorizer: "text2vec-openai" ) @@ -73,9 +73,6 @@ client.schema.get(class_name: 'Question') # Get the schema client.schema.list() -# Remove a class (and all data in the instances) from the schema. -client.schema.delete(class_name: 'Question') - # Update settings of an existing schema class. # Does not support modifying existing properties. client.schema.update( @@ -94,6 +91,52 @@ client.schema.add_property( # Inspect the shards of a class client.schema.shards(class_name: 'Question') + +# Remove a class (and all data in the instances) from the schema. +client.schema.delete(class_name: 'Question') + +# Creating a new data object class in the schema while configuring the vectorizer on the schema and on individual properties (Ollama example) +client.schema.create( + class_name: 'Question', + description: 'Information from a Jeopardy! question', + properties: [ + { + "dataType": ["text"], + "description": "The question", + "name": "question" + # By default all properties are included in the vector + }, { + "dataType": ["text"], + "description": "The answer", + "name": "answer", + "moduleConfig": { + "text2vec-ollama": { + "skip": false, + "vectorizePropertyName": true, + }, + }, + }, { + "dataType": ["text"], + "description": "The category", + "name": "category", + "indexFilterable": true, + "indexSearchable": false, + "moduleConfig": { + "text2vec-ollama": { + "skip": true, # Don't include in the vector + }, + }, + } + ], + # Possible values: 'text2vec-cohere', 'text2vec-ollama', 'text2vec-openai', 'text2vec-huggingface', 'text2vec-transformers', 'text2vec-contextionary', 'img2vec-neural', 'multi2vec-clip', 'ref2vec-centroid' + vectorizer: "text2vec-ollama", + module_config: { + "text2vec-ollama": { + apiEndpoint: "http://localhost:11434", + model: "mxbai-embed-large", + }, + }, +) ``` ### Using the Objects endpoint diff --git a/lib/weaviate/client.rb b/lib/weaviate/client.rb index 7f1cbfb..d957ac7 100644 --- a/lib/weaviate/client.rb +++ b/lib/weaviate/client.rb @@ -10,6 +10,7 @@ class Client API_VERSION = "v1" API_KEY_HEADERS = { + ollama: "X-Ollama-Not-Used", openai: "X-OpenAI-Api-Key", azure_openai: "X-Azure-Api-Key", cohere: "X-Cohere-Api-Key", From 20d29a0840b602f54056052d146e510946096f1a Mon Sep 17 00:00:00 2001 From: Cameron McCord Date: Tue, 2 Jul 2024 09:43:30 -0400 Subject: [PATCH 2/2] Remove duplicate listing of available options for vectorizers --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index 1344565..1ae9c12 100644 --- a/README.md +++ b/README.md @@ -128,7 +128,6 @@ client.schema.create( }, } ], - # Possible values: 'text2vec-cohere', 'text2vec-ollama', 'text2vec-openai', 'text2vec-huggingface', 'text2vec-transformers', 'text2vec-contextionary', 'img2vec-neural', 'multi2vec-clip', 'ref2vec-centroid' vectorizer: "text2vec-ollama", module_config: { "text2vec-ollama": {