Develop AI applications using Weaviate's APIs and tools
Deploy
Deploy, configure, and maintain Weaviate Database
Weaviate Agents
Build and deploy intelligent agents with Weaviate
Weaviate Cloud
Manage and scale Weaviate in the cloud
Additional resources
Integrations
Contributor guide
Events & Workshops
Weaviate Academy
Need help?
Ask AI Assistant⌘K
Community Forum
Added in 1.27.10, 1.28.3, 1.29.0
Weaviate Embeddings
Weaviate Cloud only
Configure a Weaviate vector index to use a Weaviate Embeddings model, and Weaviate will generate embeddings for various operations using the specified model and your Weaviate API key. This feature is called the vectorizer.
At import time, Weaviate generates text object embeddings and saves them into the index. For vector and hybrid search operations, Weaviate converts text queries into embeddings.
A Weaviate Cloud instance running at least Weaviate version >=1.27.10, >=1.28.3 or >=1.29.0.
A Weaviate client library that supports Weaviate Embeddings:
Python client version 4.9.5 or higher
JavaScript/TypeScript client version 3.2.5 or higher
Go/Java clients are not yet officially supported; you must pass the X-Weaviate-Api-Key and X-Weaviate-Cluster-Url headers manually upon instantiation as shown below.
The Weaviate Embeddings vectorizer is only available for use by Weaviate Cloud instances. At this time, Weaviate Embeddings is not available for self-hosted users.
Weaviate Embeddings is integrated with Weaviate Cloud. Your Weaviate Cloud credentials will be used to authorize your Weaviate Cloud instance's access for Weaviate Embeddings.
More infoCode snippets in the documentation reflect the latest client library and Weaviate Database version. Check the Release notes for specific versions.
If a snippet doesn't work or you have feedback, please open a GitHub issue.
import weaviate from weaviate.classes.init import Auth import os # Best practice: store your credentials in environment variables weaviate_url = os.getenv("WEAVIATE_URL") weaviate_key = os.getenv("WEAVIATE_API_KEY") client = weaviate.connect_to_weaviate_cloud( cluster_url=weaviate_url,# Weaviate URL: "REST Endpoint" in Weaviate Cloud console auth_credentials=Auth.api_key(weaviate_key),# Weaviate API key: "ADMIN" API key in Weaviate Cloud console ) print(client.is_ready())# Should print: `True` # Work with Weaviate client.close()
import weaviate from'weaviate-client' // Best practice: store your credentials in environment variables const weaviateUrl = process.env.WEAVIATE_URLasstring;// Weaviate URL: "REST Endpoint" in Weaviate Cloud console const weaviateApiKey = process.env.WEAVIATE_API_KEYasstring;// Weaviate API key: "ADMIN" API key in Weaviate Cloud console const client =await weaviate.connectToWeaviateCloud( weaviateUrl, { authCredentials:newweaviate.ApiKey(weaviateApiKey), } ) // Work with Weaviate client.close()
// Best practice: store your credentials in environment variables // WEAVIATE_HOSTNAME Weaviate hostname: "REST Endpoint" in Weaviate Cloud console // WEAVIATE_API_KEY Weaviate API key: "ADMIN" API key in Weaviate Cloud console package main import( "context" "fmt" "os" "github.com/weaviate/weaviate-go-client/v5/weaviate" "github.com/weaviate/weaviate-go-client/v5/weaviate/auth" ) funcmain(){ cfg := weaviate.Config{ Host: os.Getenv("WEAVIATE_HOSTNAME"), Scheme:"https", AuthConfig: auth.ApiKey{Value: os.Getenv("WEAVIATE_API_KEY")}, } client, err := weaviate.NewClient(cfg) if err !=nil{ fmt.Println(err) } // Work with Weaviate }
// Best practice: store your credentials in environment variables String weaviateUrl =System.getenv("WEAVIATE_URL"); String weaviateApiKey =System.getenv("WEAVIATE_API_KEY"); WeaviateClient client =WeaviateClient.connectToWeaviateCloud(weaviateUrl,// Replace with your // Weaviate Cloud URL weaviateApiKey // Replace with your Weaviate Cloud key ); System.out.println(client.isReady());// Should print: `True` client.close();// Free up resources
importio.weaviate.client.Config; importio.weaviate.client.WeaviateAuthClient; importio.weaviate.client.WeaviateClient; importio.weaviate.client.base.Result; publicclassConnectWeaviateEmbeddingsTest{ publicvoidshouldConnectToWeaviate()throwsException{ // Best practice: store your credentials in environment variables String weaviateHost =System.getenv("WEAVIATE_HOSTNAME");// Weaviate hostname: "REST Endpoint" in Weaviate Cloud console String weaviateKey =System.getenv("WEAVIATE_API_KEY");// Weaviate API key: "ADMIN" API key in Weaviate Cloud console Config config =newConfig("https", weaviateHost); WeaviateClient client =WeaviateAuthClient.apiKey(config, weaviateKey); // check the result Result<Boolean> result = client.misc().readyChecker().run(); System.out.println(result.getResult()); } }
More infoCode snippets in the documentation reflect the latest client library and Weaviate Database version. Check the Release notes for specific versions.
If a snippet doesn't work or you have feedback, please open a GitHub issue.
from weaviate.classes.config import Configure client.collections.create( "DemoCollection", vector_config=[ Configure.Vectors.text2vec_weaviate( name="title_vector", source_properties=["title"] ) ], # Additional parameters not shown )
// package, imports not shown funcmain(){ // Instantiation not shown ctx := context.Background() // Define the collection basicWeaviateVectorizerDef :=&models.Class{ Class:"DemoCollection", VectorConfig:map[string]models.VectorConfig{ "title_vector":{ Vectorizer:map[string]interface{}{ "text2vec-weaviate":map[string]interface{}{}, }, }, }, } // add the collection err = client.Schema().ClassCreator().WithClass(basicWeaviateVectorizerDef).Do(ctx) if err !=nil{ panic(err) } }
client.collections.create("DemoCollection", col -> col .vectorConfig( VectorConfig.text2vecWeaviate("title_vector", c -> c.sourceProperties("title"))) .properties(Property.text("title"),Property.text("description")));
More infoCode snippets in the documentation reflect the latest client library and Weaviate Database version. Check the Release notes for specific versions.
If a snippet doesn't work or you have feedback, please open a GitHub issue.
from weaviate.classes.config import Configure client.collections.create( "DemoCollection", vector_config=[ Configure.Vectors.text2vec_weaviate( name="title_vector", source_properties=["title"], model="Snowflake/snowflake-arctic-embed-l-v2.0" ) ], # Additional parameters not shown )
// package, imports not shown funcmain(){ // Instantiation not shown ctx := context.Background() // Define the collection weaviateVectorizerWithModelDef :=&models.Class{ Class:"DemoCollection", VectorConfig:map[string]models.VectorConfig{ "title_vector":{ Vectorizer:map[string]interface{}{ "text2vec-weaviate":map[string]interface{}{ "model":"arctic-embed-l-v2.0", }, }, }, }, } // add the collection err = client.Schema().ClassCreator().WithClass(weaviateVectorizerWithModelDef).Do(ctx) if err !=nil{ panic(err) } }
client.collections .create("DemoCollection", col -> col .vectorConfig(VectorConfig.text2vecWeaviate("title_vector", c -> c.sourceProperties("title") .model("Snowflake/snowflake-arctic-embed-l-v2.0"))) .properties(Property.text("title"),Property.text("description")));
More infoCode snippets in the documentation reflect the latest client library and Weaviate Database version. Check the Release notes for specific versions.
If a snippet doesn't work or you have feedback, please open a GitHub issue.
from weaviate.classes.config import Configure client.collections.create( "DemoCollection", vector_config=[ Configure.Vectors.text2vec_weaviate( name="title_vector", source_properties=["title"], model="Snowflake/snowflake-arctic-embed-m-v1.5", # Further options # dimensions=256 # base_url="<custom_weaviate_embeddings_url>", ) ], # Additional parameters not shown )
More infoCode snippets in the documentation reflect the latest client library and Weaviate Database version. Check the Release notes for specific versions.
If a snippet doesn't work or you have feedback, please open a GitHub issue.
source_objects =[ {"title":"The Shawshank Redemption","description":"A wrongfully imprisoned man forms an inspiring friendship while finding hope and redemption in the darkest of places."}, {"title":"The Godfather","description":"A powerful mafia family struggles to balance loyalty, power, and betrayal in this iconic crime saga."}, {"title":"The Dark Knight","description":"Batman faces his greatest challenge as he battles the chaos unleashed by the Joker in Gotham City."}, {"title":"Jingle All the Way","description":"A desperate father goes to hilarious lengths to secure the season's hottest toy for his son on Christmas Eve."}, {"title":"A Christmas Carol","description":"A miserly old man is transformed after being visited by three ghosts on Christmas Eve in this timeless tale of redemption."} ] collection = client.collections.use("DemoCollection") with collection.batch.fixed_size(batch_size=200)as batch: for src_obj in source_objects: # The model provider integration will automatically vectorize the object batch.add_object( properties={ "title": src_obj["title"], "description": src_obj["description"], }, # vector=vector # Optionally provide a pre-obtained vector ) if batch.number_errors >10: print("Batch import stopped due to excessive errors.") break failed_objects = collection.batch.failed_objects if failed_objects: print(f"Number of failed imports: {len(failed_objects)}") print(f"First failed object: {failed_objects[0]}")
let srcObjects =[ { title:"The Shawshank Redemption", description:"A wrongfully imprisoned man forms an inspiring friendship while finding hope and redemption in the darkest of places."}, { title:"The Godfather", description:"A powerful mafia family struggles to balance loyalty, power, and betrayal in this iconic crime saga."}, { title:"The Dark Knight", description:"Batman faces his greatest challenge as he battles the chaos unleashed by the Joker in Gotham City."}, { title:"Jingle All the Way", description:"A desperate father goes to hilarious lengths to secure the season's hottest toy for his son on Christmas Eve."}, { title:"A Christmas Carol", description:"A miserly old man is transformed after being visited by three ghosts on Christmas Eve in this timeless tale of redemption."} ]; const collectionName ='DemoCollection' const myCollection = client.collections.use(collectionName) let dataObjects =newArray(); for(let srcObject of srcObjects){ dataObjects.push({ title: srcObject.title, description: srcObject.description, }); } const response =await myCollection.data.insertMany(dataObjects); console.log(response);
// package, imports not shown funcmain(){ // Instantiation not shown ctx := context.Background() var sourceObjects =[]map[string]string{ {"title":"The Shawshank Redemption","description":"A wrongfully imprisoned man forms an inspiring friendship while finding hope and redemption in the darkest of places."}, {"title":"The Godfather","description":"A powerful mafia family struggles to balance loyalty, power, and betrayal in this iconic crime saga."}, {"title":"The Dark Knight","description":"Batman faces his greatest challenge as he battles the chaos unleashed by the Joker in Gotham City."}, {"title":"Jingle All the Way","description":"A desperate father goes to hilarious lengths to secure the season's hottest toy for his son on Christmas Eve."}, {"title":"A Christmas Carol","description":"A miserly old man is transformed after being visited by three ghosts on Christmas Eve in this timeless tale of redemption."}, } // Convert items into a slice of models.Object objects :=[]models.PropertySchema{} for i :=range sourceObjects { objects =append(objects,map[string]interface{}{ // Populate the object with the data "title": sourceObjects[i]["title"], "description": sourceObjects[i]["description"], }) } // Batch write items batcher := client.Batch().ObjectsBatcher() for_, dataObj :=range objects { batcher.WithObjects(&models.Object{ Class:"DemoCollection", Properties: dataObj, }) } // Flush batchRes, err := batcher.Do(ctx) // Error handling if err !=nil{ panic(err) } for_, res :=range batchRes { if res.Result.Errors !=nil{ for_, err :=range res.Result.Errors.Error { if err !=nil{ fmt.Printf("Error details: %v\n",*err) panic(err.Message) } } } } }
// Define the source objects List<Map<String,Object>> sourceObjects =List.of(Map.of("title","The Shawshank Redemption", "description", "A wrongfully imprisoned man forms an inspiring friendship while finding hope and redemption in the darkest of places."), Map.of("title","The Godfather","description", "A powerful mafia family struggles to balance loyalty, power, and betrayal in this iconic crime saga."), Map.of("title","The Dark Knight","description", "Batman faces his greatest challenge as he battles the chaos unleashed by the Joker in Gotham City."), Map.of("title","Jingle All the Way","description", "A desperate father goes to hilarious lengths to secure the season's hottest toy for his son on Christmas Eve."), Map.of("title","A Christmas Carol","description", "A miserly old man is transformed after being visited by three ghosts on Christmas Eve in this timeless tale of redemption.")); // Get a handle to the collection CollectionHandle<Map<String,Object>> collection = client.collections.use("DemoCollection"); // Insert the data using insertMany InsertManyResponse response = collection.data.insertMany(sourceObjects.toArray(newMap[0])); // Check for errors if(!response.errors().isEmpty()){ System.err.printf("Number of failed imports: %d\n", response.errors().size()); System.err.printf("First failed object error: %s\n", response.errors().get(0)); }else{ System.out.printf("Successfully inserted %d objects.\n", response.uuids().size()); }
List<HashMap<String,Object>> objects =newArrayList<>(); for(Map<String,String> sourceObject : sourceObjects){ HashMap<String,Object> schema =newHashMap<>(); schema.put("title", sourceObject.get("title")); schema.put("description", sourceObject.get("description")); objects.add(schema); } // Batch write items ObjectsBatcher batcher = client.batch().objectsBatcher(); for(Map<String,Object> properties : objects){ batcher.withObject(WeaviateObject.builder() .className("DemoCollection") .properties(properties) // .tenant("tenantA") // If multi-tenancy is enabled, specify the tenant to which the object will be added. .build() ); } // Flush batcher.run();
Re-use existing vectors
If you already have a compatible model vector available, you can provide it directly to Weaviate. This can be useful if you have already generated embeddings using the same model and want to use them in Weaviate, such as when migrating data from another system.
When you perform a vector search, Weaviate converts the text query into an embedding using the specified model and returns the most similar objects from the database.
The query below returns the n most similar objects from the database, set by limit.
More infoCode snippets in the documentation reflect the latest client library and Weaviate Database version. Check the Release notes for specific versions.
If a snippet doesn't work or you have feedback, please open a GitHub issue.
collection = client.collections.use("DemoCollection") response = collection.query.near_text( query="A holiday film",# The model provider integration will automatically vectorize the query limit=2 ) for obj in response.objects: print(obj.properties["title"])
const collectionName ='DemoCollection' const myCollection = client.collections.use(collectionName) let result; result =await myCollection.query.nearText( 'A holiday film',// The model provider integration will automatically vectorize the query { limit:2, } ) console.log(JSON.stringify(result.objects,null,2));
CollectionHandle<Map<String,Object>> collection = client.collections.use("DemoCollection"); var response = collection.query.nearText("A holiday film",// The model provider integration will automatically vectorize the query q -> q.limit(2).returnMetadata(Metadata.DISTANCE)); for(var o : response.objects()){ System.out.println(o.properties().get("title")); }
A hybrid search performs a vector search and a keyword (BM25) search, before combining the results to return the best matching objects from the database.
When you perform a hybrid search, Weaviate converts the text query into an embedding using the specified model and returns the best scoring objects from the database.
The query below returns the n best scoring objects from the database, set by limit.
More infoCode snippets in the documentation reflect the latest client library and Weaviate Database version. Check the Release notes for specific versions.
If a snippet doesn't work or you have feedback, please open a GitHub issue.
collection = client.collections.use("DemoCollection") response = collection.query.hybrid( query="A holiday film",# The model provider integration will automatically vectorize the query limit=2 ) for obj in response.objects: print(obj.properties["title"])
const collectionName ='DemoCollection' const myCollection = client.collections.use(collectionName) result =await myCollection.query.hybrid( 'A holiday film',// The model provider integration will automatically vectorize the query { limit:2, } ) console.log(JSON.stringify(result.objects,null,2));
Once the integrations are configured at the collection, the data management and search operations in Weaviate work identically to any other collection. See the following model-agnostic examples: