Vectorizer and vector index config
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.
- Python Client v4
- Python Client v3
- JS/TS Client v3
- JS/TS Client v2
- Java
- Go
from weaviate.classes.config import Configure, Property, DataType
client.collections.create(
"Article",
vectorizer_config=Configure.Vectorizer.text2vec_openai(),
properties=[ # properties configuration is optional
Property(name="title", data_type=DataType.TEXT),
Property(name="body", data_type=DataType.TEXT),
]
)
class_obj = {
"class": "Article",
"properties": [
{
"name": "title",
"dataType": ["text"],
},
],
"vectorizer": "text2vec-openai" # this could be any vectorizer
}
client.schema.create_class(class_obj)
import { vectorizer, dataType } from 'weaviate-client';
await client.collections.create({
name: 'Article',
vectorizers: vectorizer.text2VecOpenAI(),
properties: [
{ name: 'title', dataType: dataType.TEXT },
{ name: 'body', dataType: dataType.TEXT },
],
})
const classWithVectorizer = {
class: 'Article',
properties: [
{
name: 'title',
dataType: ['text'],
},
],
vectorizer: 'text2vec-openai', // this could be any vectorizer
};
// Add the class to the schema
result = await client.schema.classCreator().withClass(classWithVectorizer).do();
// Additional configuration not shown
// Define the vectorizer in the WeaviateClass Builder
WeaviateClass articleCollection = WeaviateClass.builder()
.className(collectionName)
.properties(Arrays.asList(titleProperty, bodyProperty))
.vectorizer("text2vec-openai") // Vectorize of your choic e.g. text2vec-openai or text2vec-cohere
.build();
// Add the collection to the schema
Result<Boolean> result = client.schema().classCreator()
.withClass(articleCollection)
.run();
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(),
},
},
}
Specify vectorizer settings
To configure how a vectorizer works (i.e. what model to use) with a specific collection, set the vectorizer parameters.
- Python Client v4
- Python Client v3
- JS/TS Client v3
- JS/TS Client v2
- Java
- Go
from weaviate.classes.config import Configure
client.collections.create(
"Article",
vectorizer_config=Configure.Vectorizer.text2vec_cohere(
model="embed-multilingual-v2.0",
vectorize_collection_name=True
),
)
class_obj = {
"class": "Article",
"vectorizer": "text2vec-cohere", # this could be any vectorizer
"moduleConfig": {
"text2vec-cohere": { # this must match the vectorizer used
"vectorizeClassName": True,
"model": "embed-multilingual-v2.0",
}
}
}
client.schema.create_class(class_obj)
import { vectorizer } from 'weaviate-client';
await client.collections.create({
name: 'Article',
vectorizers: vectorizer.text2VecCohere({
model: 'embed-multilingual-v2.0',
vectorizeCollectionName: true,
}),
})
const classWithModuleSettings = {
class: 'Article',
properties: [
{
name: 'title',
dataType: ['text'],
},
],
vectorizer: 'text2vec-cohere', // this could be any vectorizer
moduleConfig: {
'text2vec-cohere': {
// this must match the vectorizer used
vectorizeClassName: true,
model: 'embed-multilingual-v2.0',
},
},
};
// Add the class to the schema
result = await client.schema
.classCreator()
.withClass(classWithModuleSettings)
.do();
// Additional configuration not shown
// Define the module settings
Map<String, Object> text2vecOpenAI = new HashMap<>();
Map<String, Object> text2vecOpenAISettings = new HashMap<>();
text2vecOpenAISettings.put("vectorizePropertyName", false);
text2vecOpenAISettings.put("model", "text-embedding-3-small"); // set the model of your choice e.g. //
// text-embedding-3-small
text2vecOpenAI.put("text2vec-openai", text2vecOpenAISettings);
Map<Object, Object> moduleConfig = new HashMap<>();
moduleConfig.put("text2vec-openai", text2vecOpenAI);
// Set the module configu in the WeaviateClass Builder
WeaviateClass articleCollection = WeaviateClass.builder()
.className(collectionName)
.properties(Arrays.asList(titleProperty, bodyProperty))
.moduleConfig(moduleConfig) // Set the module config
.build();
// Add the collection to the schema
Result<Boolean> result = client.schema().classCreator()
.withClass(articleCollection)
.run();
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,
},
},
}
Define named vectors
v1.24
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.
- Python Client v4
- Python Client v3
- JS/TS Client v3
- JS/TS Client v2
- Java
- Go
from weaviate.classes.config import Configure, Property, DataType
client.collections.create(
"ArticleNV",
vectorizer_config=[
# Set a named vector with the "text2vec-cohere" vectorizer
Configure.NamedVectors.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.NamedVectors.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.NamedVectors.none(
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),
],
)
# Unfortunately, named vectors are not suppored in the v3 API / Python client.
# Please upgrade to the v4 API / Python client to use named vectors.
import { vectorizer, dataType } from 'weaviate-client';
await client.collections.create({
name: 'ArticleNV',
vectorizers: [
// Set a named vector with the "text2vec-cohere" vectorizer
vectorizer.text2VecCohere({
name: 'title',
sourceProperties: ['title'], // (Optional) Set the source property(ies)
vectorIndexConfig: configure.vectorIndex.hnsw() // (Optional) Set the vector index configuration
}),
// Set a named vector with the "text2vec-openai" vectorizer
vectorizer.text2VecOpenAI({
name: 'title_country',
sourceProperties: ['title','country'], // (Optional) Set the source property(ies)
vectorIndexConfig: configure.vectorIndex.hnsw() // (Optional) Set the vector index configuration
}),
// Set a named vector for your own uploaded vectors
vectorizer.none({
name: 'custom_vector',
vectorIndexConfig: configure.vectorIndex.hnsw() // (Optional) Set the vector index configuration
})
],
properties: [
{ name: 'title', dataType: dataType.TEXT },
{ name: 'country', dataType: dataType.TEXT },
],
})
const classWithNamedVectors = {
class: 'ArticleNV',
vectorConfig: {
// Set a named vector with the "text2vec-cohere" vectorizer
title: {
vectorizer: {
'text2vec-cohere': {
properties: ['title'], // (Optional) Set the source property(ies)
},
},
vectorIndexType: 'hnsw', // (Optional) Set the vector index type
vectorIndexConfig: {} // (Optional) Set the vector index configuration
},
// Set a named vector with the "text2vec-openai" vectorizer
title_country: {
vectorizer: {
'text2vec-openai': {
properties: ['title','country'], // (Optional) Set the source property(ies)
},
},
vectorIndexType: 'hnsw', // (Optional) Set the vector index type
vectorIndexConfig: {} // (Optional) Set the vector index configuration
},
// Set a named vector for your own uploaded vectors
custom_vector: {
vectorizer: {
'none': {}
},
vectorIndexType: 'hnsw', // (Optional) Set the vector index type
vectorIndexConfig: {} // (Optional) Set the vector index configuration
},
},
properties: [
{
name: 'title',
dataType: ['text'],
},
{
name: 'country',
dataType: ['text'],
},
],
};
// Add the class to the schema
result = await client.schema
.classCreator()
.withClass(classWithNamedVectors)
.do();
// Additional configuration not shown
// Define the vectorizers configurations
Map<String, Object> text2vecOpenAI = new HashMap<>();
Map<String, Object> text2vecOpenAISettings = new HashMap<>();
text2vecOpenAISettings.put("properties", new String[] { "name" });
text2vecOpenAI.put("text2vec-openai", text2vecOpenAISettings);
Map<String, Object> text2vecCohere = new HashMap<>();
Map<String, Object> text2vecCohereSettings = new HashMap<>();
text2vecCohereSettings.put("properties", new String[] { "body" });
text2vecCohere.put("text2vec-cohere", text2vecCohereSettings);
// Define the vector configurations
Map<String, WeaviateClass.VectorConfig> vectorConfig = new HashMap<>();
vectorConfig.put("name_vector", WeaviateClass.VectorConfig.builder()
.vectorIndexType("hnsw")
.vectorizer(text2vecOpenAI)
.build());
vectorConfig.put("body_vector", WeaviateClass.VectorConfig.builder()
.vectorIndexType("hnsw")
.vectorizer(text2vecCohere)
.build());
// Define the vectorizers in the WeaviateClass Builder
WeaviateClass articleCollection = WeaviateClass.builder()
.className(collectionName)
.properties(Arrays.asList(titleProperty, bodyProperty))
.vectorConfig(vectorConfig)
.build();
// Add the collection to the schema
Result<Boolean> result = client.schema().classCreator()
.withClass(articleCollection)
.run();
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{}{
"sourceProperties": []string{"title"},
},
},
VectorIndexType: "hnsw",
},
"title_country": {
Vectorizer: map[string]interface{}{
"text2vec-openai": map[string]interface{}{
"sourceProperties": []string{"title", "country"},
},
},
VectorIndexType: "hnsw",
},
"custom_vector": {
Vectorizer: map[string]interface{}{
"none": map[string]interface{}{},
},
VectorIndexType: "hnsw",
},
},
}
Add new named vectors
v1.31
Named vectors can be added to existing collection definitions with named vectors. (This is not possible for collections without named vectors.)
- Python Client v4
- JS/TS Client v3
- Java
- Go
from weaviate.classes.config import Configure
articles = client.collections.get("Article")
articles.config.add_vector(
vector_config=Configure.NamedVectors.text2vec_cohere(
name="body_vector",
source_properties=["body"],
)
)
// TS support coming soon
// Java support coming soon
// Go support coming soon
Adding a new named vector to the collection definition won't trigger vectorization for existing objects. Only new or updated objects will receive embeddings for the newly added named vector definition.
Define multi-vector embeddings (e.g. ColBERT, ColPali)
v1.29
, v1.30
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.
- Python Client v4
- Java
from weaviate.classes.config import Configure, Property, DataType
client.collections.create(
"DemoCollection",
vectorizer_config=[
# Example 1 - Use a model integration
# The factory function will automatically enable multi-vector support for the HNSW index
Configure.NamedVectors.text2colbert_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.NamedVectors.none(
name="custom_multi_vector",
vector_index_config=Configure.VectorIndex.hnsw(
multi_vector=Configure.VectorIndex.MultiVector.multi_vector()
),
),
],
properties=[
Property(name="text", data_type=DataType.TEXT)
]
# Additional parameters not shown
)
// Define collection properties
Property textProperty = Property.builder()
.name("text")
.description("Text content for ColBERT vectorization")
.dataType(Arrays.asList(DataType.TEXT))
.build();
// Define the vectorizers configurations for named vectors
Map<String, Object> text2colbertJinaAI = new HashMap<>();
Map<String, Object> text2colbertSettings = new HashMap<>();
text2colbertSettings.put("properties", new String[] { "text" });
text2colbertJinaAI.put("text2colbert-jinaai", text2colbertSettings);
// Configure multi-vector for custom vectors
Map<String, Object> noneVectorizer = new HashMap<>();
noneVectorizer.put("none", new Object());
// Create multi-vector config for custom vectors
VectorIndexConfig customMultiVectorConfig = VectorIndexConfig.builder()
.multiVector(MultiVectorConfig.builder().build()) // Enable multi-vector with default settings
.build();
// Define the vector configurations
Map<String, WeaviateClass.VectorConfig> vectorConfig = new HashMap<>();
// Example 1: ColBERT vectorizer
vectorConfig.put("jina_colbert", WeaviateClass.VectorConfig.builder()
.vectorIndexType("hnsw")
.vectorizer(text2colbertJinaAI)
.build());
// Example 2: User-provided multi-vector representations
vectorConfig.put("custom_multi_vector", WeaviateClass.VectorConfig.builder()
.vectorIndexType("hnsw")
.vectorizer(noneVectorizer)
.vectorIndexConfig(customMultiVectorConfig)
.build());
// Create the collection with multi-vector configuration
WeaviateClass multiVecClass = WeaviateClass.builder()
.className(collectionName)
.properties(Arrays.asList(textProperty))
.vectorConfig(vectorConfig)
.build();
// Add the collection to the schema
Result<Boolean> result = client.schema().classCreator()
.withClass(multiVecClass)
.run();
Multi-vector embeddings use up more memory than single vector embeddings. You can use vector quantization and encoding to compress them and reduce memory usage.
Set vector index type
The vector index type can be set for each collection at creation time, between hnsw
, flat
and dynamic
index types.
- Python Client v4
- Python Client v3
- JS/TS Client v3
- JS/TS Client v2
- Java
- Go
from weaviate.classes.config import Configure, Property, DataType
client.collections.create(
"Article",
vectorizer_config=Configure.Vectorizer.text2vec_openai(),
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
properties=[
Property(name="title", data_type=DataType.TEXT),
Property(name="body", data_type=DataType.TEXT),
]
)
class_obj = {
'class': 'Article',
'properties': [
{
'name': 'title',
'dataType': ['text'],
},
],
'vectorizer': 'text2vec-openai', # this could be any vectorizer
"vectorIndexType": "hnsw", # or "flat" or "dynamic"
}
client.schema.create_class(class_obj)
import { vectorizer, dataType, configure } from 'weaviate-client';
await client.collections.create({
name: 'Article',
vectorizers: vectorizer.text2VecOpenAI({
vectorIndexConfig: configure.vectorIndex.hnsw(), // Use HNSW
// vectorIndexConfig: configure.vectorIndex.flat(), // Use Flat
// vectorIndexConfig: configure.vectorIndex.dynamic(), // Use Dynamic
}),
properties: [
{ name: 'title', dataType: dataType.TEXT },
{ name: 'body', dataType: dataType.TEXT },
],
})
const classWithIndexType = {
class: 'Article',
properties: [
{
name: 'title',
dataType: ['text'],
},
],
vectorizer: 'text2vec-openai', // this could be any vectorizer
vectorIndexType: 'flat', // or 'hnsw', or 'dynamic'
vectorIndexConfig: {
bq: {
enabled: true, // Enable BQ compression. Default: False
rescoreLimit: 200, // The minimum number of candidates to fetch before rescoring. Default: -1 (No limit)
cache: true, // Enable use of vector cache. Default: False
},
vectorCacheMaxObjects: 100000, // Cache size if `cache` enabled. Default: 1000000000000
},
};
// Add the class to the schema
result = await client.schema.classCreator().withClass(classWithIndexType).do();
// Additional configuration not shown
// Define the index type in the WeaviateClass Builder
WeaviateClass articleCollection = WeaviateClass.builder()
.className(collectionName)
.properties(Arrays.asList(titleProperty, bodyProperty))
.vectorizer("text2vec-openai")
.vectorIndexType("hnsw") // set the vector index of your choice e.g. hnsw, flat...
.build();
// Add the collection to the schema
Result<Boolean> result = client.schema().classCreator()
.withClass(articleCollection)
.run();
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"
}
Additional information
- Read more about index types & compression in Concepts: Vector index.
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.
Was added in v1.27
- Python Client v4
- Python Client v3
- JS/TS Client v3
- JS/TS Client v2
- Java
- Go
from weaviate.classes.config import Configure, Property, DataType, VectorDistances, VectorFilterStrategy
client.collections.create(
"Article",
# Additional configuration not shown
vector_index_config=Configure.VectorIndex.hnsw(
quantizer=Configure.VectorIndex.Quantizer.bq(),
ef_construction=300,
distance_metric=VectorDistances.COSINE,
filter_strategy=VectorFilterStrategy.SWEEPING # or ACORN (Available from Weaviate v1.27.0)
),
)
class_obj = {
'class': 'Article',
# Additional configuration not shown
"vectorIndexType": "flat",
"vectorIndexConfig": {
"bq": {
"enabled": True, # Enable BQ compression. Default: False
"rescoreLimit": 200, # The minimum number of candidates to fetch before rescoring. Default: -1 (No limit)
"cache": True, # Enable use of vector cache. Default: False
},
"vectorCacheMaxObjects": 100000, # Cache size if `cache` enabled. Default: 1000000000000
"filterStrategy": "sweeping" # or "acorn" (Available from Weaviate v1.27.0)
}
}
client.schema.create_class(class_obj)
import { configure, vectorizer } from 'weaviate-client';
await client.collections.create({
name: 'Article',
// Additional configuration not shown
vectorizers: vectorizer.text2VecCohere({
vectorIndexConfig: configure.vectorIndex.flat({
quantizer: configure.vectorIndex.quantizer.bq({
rescoreLimit: 200,
cache: true
}),
vectorCacheMaxObjects: 100000
})
})
})
const classWithIndexParams = {
class: 'Article',
// Additional configuration not shown
vectorIndexType: 'flat', // or `hnsw`
vectorIndexConfig: {
bq: {
enabled: true, // Enable BQ compression. Default: False
rescoreLimit: 200, // The minimum number of candidates to fetch before rescoring. Default: -1 (No limit)
cache: true, // Enable use of vector cache. Default: False
},
vectorCacheMaxObjects: 100000, // Cache size if `cache` enabled. Default: 1000000000000
},
};
// Add the class to the schema
result = await client.schema.classCreator().withClass(classWithIndexType).do();
// Additional configuration not shown
// Define the VectorIndexConfig with compression
VectorIndexConfig createBqIndexConfig = VectorIndexConfig.builder()
.bq(BQConfig.builder()
.enabled(true)
.rescoreLimit(123L)
.cache(true)
.build())
.vectorCacheMaxObjects(100000L)
.build();
WeaviateClass articleCollection = WeaviateClass.builder()
.className(collectionName)
.properties(Arrays.asList(titleProperty, bodyProperty))
.vectorIndexType("flat") // set the vector index of your choice e.g. hnsw, flat...
.vectorIndexConfig(createBqIndexConfig)
.vectorizer("text2vec-openai")
.build();
// Add the collection to the schema
Result<Boolean> result = client.schema().classCreator()
.withClass(articleCollection)
.run();
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",
},
}
Additional information
- Read more about index types & compression in Concepts: Vector index.
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
- Python Client v4
- Python Client v3
- JS/TS Client v3
- JS/TS Client v2
- Java
- Go
from weaviate.classes.config import Configure, Property, DataType, Tokenization
client.collections.create(
"Article",
vectorizer_config=Configure.Vectorizer.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 "lowecase" 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
),
]
)
class_obj = {
"class": "Article",
"vectorizer": "text2vec-huggingface", # this could be any vectorizer
"properties": [
{
"name": "title",
"dataType": ["text"],
"moduleConfig": {
"text2vec-huggingface": { # this must match the vectorizer used
"vectorizePropertyName": True,
"tokenization": "lowercase"
}
}
},
{
"name": "body",
"dataType": ["text"],
"moduleConfig": {
"text2vec-huggingface": { # this must match the vectorizer used
"skip": True, # Don't vectorize body
"tokenization": "whitespace"
}
}
},
],
}
client.schema.create_class(class_obj)
import { vectorizer, dataType, tokenization } from 'weaviate-client';
const newCollection = await client.collections.create({
name: 'Article',
vectorizers: vectorizer.text2VecHuggingFace(),
properties: [
{
name: 'title',
dataType: dataType.TEXT,
vectorizePropertyName: true,
tokenization: tokenization.LOWERCASE // or 'lowercase'
},
{
name: 'body',
dataType: dataType.TEXT,
skipVectorization: true,
tokenization: tokenization.WHITESPACE // or 'whitespace'
},
],
})
const classWithPropModuleSettings = {
class: 'Article',
vectorizer: 'text2vec-huggingface', // this could be any vectorizer
properties: [
{
name: 'title',
dataType: ['text'],
moduleConfig: {
'text2vec-huggingface': {
// this must match the vectorizer used
vectorizePropertyName: true,
tokenization: 'lowercase', // Use "lowercase" tokenization
},
},
},
{
name: 'body',
dataType: ['text'],
moduleConfig: {
'text2vec-huggingface': {
// this must match the vectorizer used
skip: true, // Don't vectorize this property
tokenization: 'whitespace', // Use "whitespace" tokenization
},
},
},
],
};
// Add the class to the schema
result = await client.schema
.classCreator()
.withClass(classWithPropModuleSettings)
.do();
Property titleProperty = Property.builder()
.name("title")
.description("title of the article")
.dataType(Arrays.asList(DataType.TEXT))
.tokenization(Tokenization.WORD)
.build();
Property bodyProperty = Property.builder()
.name("body")
.description("body of the article")
.dataType(Arrays.asList(DataType.TEXT))
.tokenization(Tokenization.LOWERCASE)
.build();
// Add the defined properties to the collection
WeaviateClass articleCollection = WeaviateClass.builder()
.className(collectionName)
.description("Article collection Description...")
.properties(Arrays.asList(titleProperty, bodyProperty))
.build();
Result<Boolean> result = client.schema().classCreator()
.withClass(articleCollection)
.run();
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",
}
Specify a distance metric
If you choose to bring your own vectors, you should specify the distance metric
.
- Python Client v4
- Python Client v3
- JS/TS Client v3
- JS/TS Client v2
- Java
- Go
from weaviate.classes.config import Configure, VectorDistances
client.collections.create(
"Article",
vector_index_config=Configure.VectorIndex.hnsw(
distance_metric=VectorDistances.COSINE
),
)
class_obj = {
"class": "Article",
"vectorIndexConfig": {
"distance": "cosine",
},
}
client.schema.create_class(class_obj)
import { configure, vectorizer, vectorDistances } from 'weaviate-client';
await client.collections.create({
name: 'Article',
vectorizers: vectorizer.text2VecOllama({
vectorIndexConfig: configure.vectorIndex.hnsw({
distanceMetric: vectorDistances.COSINE // or 'cosine'
})
})
})
const classWithDistance = {
class: 'Article',
vectorIndexConfig: {
distance: 'cosine',
},
};
// Add the class to the schema
result = await client.schema.classCreator().withClass(classWithDistance).do();
// Additional configuration not shown
VectorIndexConfig vectorIndexConfig = VectorIndexConfig.builder()
.distance(DistanceType.DOT) // Define Distance Type e.g. Dot, Cosine, hamming...
.build();
WeaviateClass articleCollection = WeaviateClass.builder()
.className(collectionName)
.properties(Arrays.asList(titleProperty, bodyProperty))
.vectorIndexConfig(vectorIndexConfig)
.build();
Result<Boolean> classResult = client.schema().classCreator()
.withClass(articleCollection)
.run();
articleClass := &models.Class{
Class: "Article",
Description: "Collection of articles",
VectorIndexConfig: map[string]interface{}{
"distance": "cosine",
},
}
Additional information
For details on the configuration parameters, see the following:
Further resources
Questions and feedback
If you have any questions or feedback, let us know in the user forum.