Vectorizer and vector index config
Specify a vectorizer
Section titled “Specify a vectorizer”Specify a vectorizer for a collection.
Additional information
Collection level settings override default values and general configuration parameters such as environment variables.
from weaviate.classes.config import Configure, Property, DataTypeclient.collections.create( "Article", vector_config=Configure.Vectors.text2vec_openai(), properties=[ Property(name="title", data_type=DataType.TEXT), Property(name="body", data_type=DataType.TEXT), ],)import { vectors, dataType } from 'weaviate-client';articleClass := &models.Class{
Class: "Article",
Description: "Collection of articles",
Vectorizer: "text2vec-openai",
Properties: []*models.Property{
{
Name: "title",
DataType: schema.DataTypeText.PropString(),
},
{
Name: "body",
DataType: schema.DataTypeText.PropString(),
},
},
}client.collections.create("Article",
col -> col.vectorConfig(VectorConfig.text2vecTransformers())
.properties(Property.text("title"), Property.text("body")));await client.Collections.Create(
new CollectionCreateParams
{
Name = "Article",
VectorConfig = new VectorConfigList
{
Configure.Vector("default", v => v.Text2VecTransformers()),
},
Properties = [Property.Text("title"), Property.Text("body")],
}
);Specify vectorizer settings
Section titled “Specify vectorizer settings”To configure how a vectorizer works (i.e. what model to use) with a specific collection, set the vectorizer parameters.
from weaviate.classes.config import Configureclient.collections.create( "Article", vector_config=Configure.Vectors.text2vec_cohere( model="embed-multilingual-v2.0", vectorize_collection_name=True ),)import { vectors } from 'weaviate-client';articleClass := &models.Class{
Class: "Article",
Description: "Collection of articles",
Vectorizer: "text2vec-cohere",
ModuleConfig: map[string]interface{}{
"text2vec-cohere": map[string]interface{}{
"model": "embed-multilingual-v2.0",
"vectorizeClassName": true,
},
},
}client.collections.create("Article", col -> col.vectorConfig(
VectorConfig.text2vecCohere(c -> c.model("embed-multilingual-v2.0"))));await client.Collections.Create(
new CollectionCreateParams
{
Name = "Article",
VectorConfig = new VectorConfigList
{
Configure.Vector(
"default",
v =>
v.Text2VecTransformers(
// The available settings depend on the module
// inferenceUrl: "http://custom-inference:8080",
// vectorizeCollectionName: false
)
),
},
Properties = [Property.Text("title"), Property.Text("body")],
}
);Define named vectors
Section titled “Define named vectors”You can define multiple named vectors per collection. This allows each object to be represented by multiple vector embeddings, each with its own vector index.
As such, each named vector configuration can include its own vectorizer and vector index settings.
from weaviate.classes.config import Configure, Property, DataTypeclient.collections.create( "ArticleNV", vector_config=[ # Set a named vector with the "text2vec-cohere" vectorizer Configure.Vectors.text2vec_cohere( name="title", source_properties=["title"], # (Optional) Set the source property(ies) vector_index_config=Configure.VectorIndex.hnsw(), # (Optional) Set vector index options ), # Set another named vector with the "text2vec-openai" vectorizer Configure.Vectors.text2vec_openai( name="title_country", source_properties=[ "title", "country", ], # (Optional) Set the source property(ies) vector_index_config=Configure.VectorIndex.hnsw(), # (Optional) Set vector index options ), # Set a named vector for your own uploaded vectors Configure.Vectors.self_provided( name="custom_vector", vector_index_config=Configure.VectorIndex.hnsw(), # (Optional) Set vector index options ), ], properties=[ # Define properties Property(name="title", data_type=DataType.TEXT), Property(name="country", data_type=DataType.TEXT), ],)import { vectors, dataType } from 'weaviate-client';articleClass := &models.Class{
Class: "ArticleNV",
Description: "Collection of articles with named vectors",
Properties: []*models.Property{
{
Name: "title",
DataType: schema.DataTypeText.PropString(),
},
{
Name: "country",
DataType: schema.DataTypeText.PropString(),
},
},
VectorConfig: map[string]models.VectorConfig{
"title": {
Vectorizer: map[string]interface{}{
"text2vec-openai": map[string]interface{}{
"properties": []string{"title"},
},
},
VectorIndexType: "hnsw",
},
"title_country": {
Vectorizer: map[string]interface{}{
"text2vec-openai": map[string]interface{}{
"properties": []string{"title", "country"},
},
},
VectorIndexType: "hnsw",
},
"custom_vector": {
Vectorizer: map[string]interface{}{
"none": map[string]interface{}{},
},
VectorIndexType: "hnsw",
},
},
}// Weaviate
client.collections
.create("ArticleNV",
col -> col
.vectorConfig(
VectorConfig.text2vecTransformers("title",
c -> c.sourceProperties("title")
.vectorIndex(Hnsw.of())),
VectorConfig.text2vecTransformers("title_country",
c -> c.sourceProperties("title", "country")
.vectorIndex(Hnsw.of())),
VectorConfig.selfProvided("custom_vector",
c -> c.vectorIndex(Hnsw.of()).vectorIndex(Hnsw.of())))
.properties(Property.text("title"), Property.text("country")));await client.Collections.Create(
new CollectionCreateParams
{
Name = "ArticleNV",
VectorConfig = new VectorConfigList
{
Configure.Vector(
"title",
v => v.Text2VecTransformers(),
sourceProperties: ["title"],
index: new VectorIndex.HNSW()
),
Configure.Vector(
"title_country",
v => v.Text2VecTransformers(),
sourceProperties: ["title", "country"],
index: new VectorIndex.HNSW()
),
Configure.Vector(
"custom_vector",
v => v.SelfProvided(),
index: new VectorIndex.HNSW()
),
},
Properties = [Property.Text("title"), Property.Text("country")],
}
);Add new named vectors
Section titled “Add new named vectors”Named vectors can be added to existing collection definitions with named vectors. (This is not possible for collections without named vectors.)
from weaviate.classes.config import Configure
articles = client.collections.use("Article")
articles.config.add_vector(
vector_config=Configure.Vectors.text2vec_cohere(
name="body_vector",
source_properties=["body"],
)
)await articles.config.addVector(
vectors.text2VecCohere({
name: "body_vector",
sourceProperties: ["body"],
})
)// Go support coming soonCollectionHandle<Map<String, Object>> collection =
client.collections.use("ArticleNV");
collection.config.update(
u -> u.vectorConfig(VectorConfig.text2vecTransformers("title_country",
c -> c.sourceProperties("title", "country")
.vectorIndex(Hnsw.of()))));await articles.Config.AddVector(
Configure.Vector("body_vector", v => v.Text2VecCohere(), sourceProperties: "body")
);Define multi-vector embeddings (e.g. ColBERT, ColPali)
Section titled “Define multi-vector embeddings (e.g. ColBERT, ColPali)”Multi-vector embeddings, also known as multi-vectors, represent a single object with multiple vectors, i.e. a 2-dimensional matrix. Multi-vectors are currently only available for HNSW indexes for named vectors. To use multi-vectors, enable it for the appropriate named vector.
from weaviate.classes.config import Configure, Property, DataTypeclient.collections.create( "DemoCollection", vector_config=[ # Example 1 - Use a model integration # The factory function will automatically enable multi-vector support for the HNSW index Configure.MultiVectors.text2vec_jinaai( name="jina_colbert", source_properties=["text"], ), # Example 2 - User-provided multi-vector representations # Must explicitly enable multi-vector support for the HNSW index Configure.MultiVectors.self_provided( name="custom_multi_vector", ), ], properties=[Property(name="text", data_type=DataType.TEXT)], # Additional parameters not shown)await client.collections.create({ name: "DemoCollection", vectorizers: [ // Example 1 - Use a model integration // The factory function will automatically enable multi-vector support for the HNSW index configure.multiVectors.text2VecJinaAI({ name: "jina_colbert", sourceProperties: ["text"], }), // Example 2 - User-provided multi-vector representations // Must explicitly enable multi-vector support for the HNSW index configure.multiVectors.selfProvided({ name: "custom_multi_vector", }), ], properties: [{ name: "text", dataType: dataType.TEXT }], // Additional parameters not shown})client.collections.create("DemoCollection", col -> col.vectorConfig( // Example 1 - Use a model integration // The factory function will automatically enable multi-vector support for the HNSW index VectorConfig.text2multivecJinaAi("jina_colbert", vc -> vc.sourceProperties("text") // In Java, explicitly configure the HNSW index for multi-vector .vectorIndex(Hnsw.of(h -> h.multiVector(MultiVector.of())))), // Example 2 - User-provided multi-vector representations // Must explicitly enable multi-vector support for the HNSW index VectorConfig.selfProvided("custom_multi_vector", vc -> vc.vectorIndex(Hnsw.of(h -> h.multiVector(MultiVector.of()))))).properties(Property.text("text"))// Additional parameters not shown);await client.Collections.Create(
new CollectionCreateParams
{
Name = "DemoCollection",
VectorConfig =
[
// Example 1 - Use a model integration
Configure.MultiVector("jina_colbert", v => v.Text2MultiVecJinaAI()),
// Example 2 - User-provided multi-vector representations
Configure.MultiVector("custom_multi_vector", v => v.SelfProvided()),
],
Properties = [Property.Text("text")],
}
);Set vector index type
Section titled “Set vector index type”The vector index type can be set for each collection at creation time, between hnsw, flat, dynamic, and hfresh index types.
from weaviate.classes.config import Configure, Property, DataTypeclient.collections.create( "Article", vector_config=Configure.Vectors.text2vec_openai( name="default", vector_index_config=Configure.VectorIndex.hnsw(), # Use the HNSW index # vector_index_config=Configure.VectorIndex.flat(), # Use the FLAT index # vector_index_config=Configure.VectorIndex.dynamic(), # Use the DYNAMIC index # vector_index_config=Configure.VectorIndex.hfresh(), # Use the HFRESH index ), properties=[ Property(name="title", data_type=DataType.TEXT), Property(name="body", data_type=DataType.TEXT), ],)import { vectors, dataType, configure } from 'weaviate-client';articleClass := &models.Class{
Class: "Article",
Description: "Collection of articles",
Properties: []*models.Property{
{
Name: "title",
DataType: schema.DataTypeText.PropString(),
},
{
Name: "country",
DataType: schema.DataTypeText.PropString(),
},
},
Vectorizer: "text2vec-openai",
VectorIndexType: "hnsw", // Or "flat", "dynamic", "hfresh"
}client.collections.create("Article",
col -> col
.vectorConfig(VectorConfig
.text2vecTransformers(vec -> vec.vectorIndex(Hnsw.of())))
.properties(Property.text("title"), Property.text("body")));await client.Collections.Create(
new CollectionCreateParams
{
Name = "Article",
VectorConfig = new VectorConfigList
{
Configure.Vector(
"default",
v => v.Text2VecTransformers(),
index: new VectorIndex.HNSW()
),
},
Properties = [Property.Text("title"), Property.Text("body")],
}
);Additional information
Read more about index types & compression in:
Set vector index parameters
Section titled “Set vector index parameters”Set vector index parameters such as compression and filter strategy through collection configuration. Some parameters can be updated later after collection creation.
from weaviate.classes.config import ( Configure, Property, DataType, VectorDistances, VectorFilterStrategy,)client.collections.create( "Article", vector_config=Configure.Vectors.text2vec_openai( name="default", vector_index_config=Configure.VectorIndex.hnsw( ef_construction=300, distance_metric=VectorDistances.COSINE, filter_strategy=VectorFilterStrategy.ACORN, ), ),)import { configure, vectors } from 'weaviate-client';articleClass := &models.Class{
Class: "Article",
Description: "Collection of articles",
Properties: []*models.Property{
{
Name: "title",
DataType: schema.DataTypeText.PropString(),
},
{
Name: "country",
DataType: schema.DataTypeText.PropString(),
},
},
Vectorizer: "text2vec-openai",
VectorIndexType: "hnsw",
VectorIndexConfig: map[string]interface{}{
"bq": map[string]interface{}{
"enabled": true,
},
"efConstruction": 300,
"distance": "cosine",
"filterStrategy": "acorn",
},
}client.collections.create("Article", col -> col
.vectorConfig(
VectorConfig.text2vecTransformers(vec -> vec.vectorIndex(Hnsw.of(
hnsw -> hnsw.efConstruction(300).distance(Distance.COSINE)))))
.properties(Property.text("title")));await client.Collections.Create(
new CollectionCreateParams
{
Name = "Article",
VectorConfig = new[]
{
Configure.Vector(
"default",
v => v.Text2VecTransformers(),
index: new VectorIndex.HNSW()
{
EfConstruction = 300,
Distance = VectorDistance.Cosine,
}
),
},
Properties = [Property.Text("title")],
}
);Additional information
Read more about index types & compression in:
Property-level settings
Section titled “Property-level settings”Configure individual properties in a collection. Each property can have it's own configuration. Here are some common settings:
- Vectorize the property
- Vectorize the property name
- Set a tokenization type
from weaviate.classes.config import Configure, Property, DataType, Tokenizationclient.collections.create( "Article", vector_config=Configure.Vectors.text2vec_cohere(), properties=[ Property( name="title", data_type=DataType.TEXT, vectorize_property_name=True, # Use "title" as part of the value to vectorize tokenization=Tokenization.LOWERCASE, # Use "lowercase" tokenization description="The title of the article.", # Optional description ), Property( name="body", data_type=DataType.TEXT, skip_vectorization=True, # Don't vectorize this property tokenization=Tokenization.WHITESPACE, # Use "whitespace" tokenization ), ],)import { vectors, dataType, tokenization } from 'weaviate-client';vTrue := true
vFalse := false
articleClass := &models.Class{
Class: "Article",
Description: "Collection of articles",
Properties: []*models.Property{
{
Name: "title",
DataType: schema.DataTypeText.PropString(),
Tokenization: "lowercase",
IndexFilterable: &vTrue,
IndexSearchable: &vFalse,
ModuleConfig: map[string]interface{}{
"text2vec-cohere": map[string]interface{}{
"vectorizePropertyName": true,
},
},
},
{
Name: "body",
DataType: schema.DataTypeText.PropString(),
Tokenization: "whitespace",
IndexFilterable: &vTrue,
IndexSearchable: &vTrue,
ModuleConfig: map[string]interface{}{
"text2vec-cohere": map[string]interface{}{
"vectorizePropertyName": false,
},
},
},
},
Vectorizer: "text2vec-cohere",
}client.collections.create("Article",
col -> col.properties(
Property.text("title",
p -> p.description("The title of the article.")
.tokenization(Tokenization.LOWERCASE)
.vectorizePropertyName(false)),
Property.text("body", p -> p.skipVectorization(true)
.tokenization(Tokenization.WHITESPACE))));await client.Collections.Create(
new CollectionCreateParams
{
Name = "Article",
Properties =
[
Property.Text("title", tokenization: PropertyTokenization.Lowercase),
Property.Text("body", tokenization: PropertyTokenization.Whitespace),
],
}
);Specify a distance metric
Section titled “Specify a distance metric”If you choose to bring your own vectors, you should specify the distance metric.
from weaviate.classes.config import Configure, VectorDistancesclient.collections.create( "Article", vector_config=Configure.Vectors.text2vec_openai( vector_index_config=Configure.VectorIndex.hnsw( distance_metric=VectorDistances.COSINE ), ),)import { configure, vectors, vectorDistances } from 'weaviate-client';articleClass := &models.Class{
Class: "Article",
Description: "Collection of articles",
VectorIndexConfig: map[string]interface{}{
"distance": "cosine",
},
}client.collections.create("Article",
col -> col
.vectorConfig(VectorConfig.text2vecTransformers(vec -> vec
.vectorIndex(Hnsw.of(hnsw -> hnsw.distance(Distance.COSINE)))))
.properties(Property.text("title")));await client.Collections.Create(
new CollectionCreateParams
{
Name = "Article",
VectorConfig = new[]
{
Configure.Vector(
"default",
v => v.Text2VecTransformers(),
index: new VectorIndex.HNSW() { Distance = VectorDistance.Cosine }
),
},
Properties = [Property.Text("title")],
}
);Additional information
For details on the configuration parameters, see the following:
Further resources
Section titled “Further resources”Questions and feedback
Section titled “Questions and feedback”Have a question or feedback? Here's how to reach us.