Skip to main content
Weaviate Docs (migrated from docs.weaviate.io) Docs

Search documentation

Type to search this documentation.

On this pageOverview

Basic collection operations

Every object in Weaviate belongs to exactly one collection. Use the examples on this page to manage your collections.

To create a collection, specify at least the collection name. If you don't specify any properties, auto-schema creates them.

Python
client.collections.create("Article")
JavaScript/TypeScript
const newCollection = await client.collections.create({
  name: 'Article'
})

// The returned value is the full collection definition, showing all defaults
console.log(JSON.stringify(newCollection, null, 2));
Go
className := "Article"
Java
client.collections.create("Article");
C#
await client.Collections.Create(new CollectionCreateParams { Name = "Article" });

Properties are the data fields in your collection. Each property has a name and a data type.

Additional information

Use properties to configure additional parameters such as data type, index characteristics, or tokenization.

For details, see:

Python
from weaviate.classes.config import Property, DataType

# Note that you can use `client.collections.create_from_dict()` to create a collection from a v3-client-style JSON object
client.collections.create(
    "Article",
    properties=[
        Property(name="title", data_type=DataType.TEXT),
        Property(name="body", data_type=DataType.TEXT),
    ],
)
TypeScript
import { dataType } from 'weaviate-client';
Go
articleClass := &models.Class{
  Class:       "Article",
  Description: "Collection of articles",
  Properties: []*models.Property{
    {
      Name:     "title",
      DataType: schema.DataTypeText.PropString(),
    },
    {
      Name:     "body",
      DataType: schema.DataTypeText.PropString(),
    },
  },
}
Java
client.collections.create("Article",
    col -> col.properties(Property.text("title"), Property.text("body")));
C#
await client.Collections.Create(
    new CollectionCreateParams
    {
        Name = "Article",
        Properties = [Property.Text("title"), Property.Text("body")],
    }
);
Or by using the fields from a class:
C#
// public class Article
// {
//     public string Title { get; set; }
//     public string Body { get; set; }
// }

await client.Collections.Create(
    new CollectionCreateParams
    {
        Name = "Article",
        Properties = [.. Property.FromClass<Article>()],
    }
);

Specify a vectorizer for a collection that will generate vector embeddings when creating objects and executing vector search queries.

Python
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),    ],)
JavaScript/TypeScript
import { vectors, dataType } from 'weaviate-client';
Go
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(),
    },
  },
}
Java
client.collections.create("Article",
    col -> col.vectorConfig(VectorConfig.text2vecTransformers())
        .properties(Property.text("title"), Property.text("body")));
C#
await client.Collections.Create(
    new CollectionCreateParams
    {
        Name = "Article",
        VectorConfig = new VectorConfigList
        {
            Configure.Vector("default", v => v.Text2VecTransformers()),
        },
        Properties = [Property.Text("title"), Property.Text("body")],
    }
);

By default, Weaviate creates missing collections and missing properties. When you configure collections manually, you have more precise control of the collection settings.

To disable auto-schema set AUTOSCHEMA_ENABLED: 'false' in your system configuration file.

Get a boolean indicating whether a given collection exists.

Python
exists = client.collections.exists("Article")  # Returns a boolean
JavaScript/TypeScript
var exists = await client.collections.exists("Article")  // Returns a boolean
Java
client.collections.exists(collectionName);
C#
bool exists = await client.Collections.Exists("Article");

Retrieve a collection definition from the schema.

Python
articles = client.collections.use("Article")
articles_config = articles.config.get()

print(articles_config)
JavaScript/TypeScript
let articles = client.collections.use('Article')
Go
className := "Article"
Java
CollectionHandle<Map<String, Object>> articles =
    client.collections.use("Article");
Optional<CollectionConfig> articlesConfig = articles.config.get();

System.out.println(articlesConfig);
C#
var articles = client.Collections.Use("Article");
var articlesConfig = await articles.Config.Get();

Console.WriteLine(articlesConfig);
Sample configuration: Text objects

This configuration for text objects defines the following:

  • The collection name (Article)
  • The vectorizer module (text2vec-cohere) and model (embed-multilingual-v2.0)
  • A set of properties (title, body) with text data types.
JSON
{
  "class": "Article",
  "vectorizer": "text2vec-cohere",
  "moduleConfig": {
    "text2vec-cohere": {
      "model": "embed-multilingual-v2.0"
    }
  },
  "properties": [
    {
      "name": "title",
      "dataType": ["text"]
    },
    {
      "name": "body",
      "dataType": ["text"]
    }
  ]
}
Sample configuration: Nested objects

This configuration for nested objects defines the following:

  • The collection name (Person)
  • The vectorizer module (text2vec-huggingface)
  • A set of properties (last_name, address)
    • last_name has text data type
    • address has object data type
  • The address property has two nested properties (street and city)
JSON
{
  "class": "Person",
  "vectorizer": "text2vec-huggingface",
  "properties": [
    {
      "dataType": ["text"],
      "name": "last_name"
    },
    {
      "dataType": ["object"],
      "name": "address",
      "nestedProperties": [
        { "dataType": ["text"], "name": "street" },
        { "dataType": ["text"], "name": "city" }
      ]
    }
  ]
}

To filter on values inside nested objects, see Filter on nested object properties.

Sample configuration: Images

This configuration for image search defines the following:

  • The collection name (Image)
  • The vectorizer module (img2vec-neural)
    • The image property configures collection to store image data.
  • The vector index distance metric (cosine)
  • A set of properties (image), with the image property set as blob.

For image searches, see Image search.

JSON
{
  "class": "Image",
  "vectorizer": "img2vec-neural",
  "vectorIndexConfig": {
    "distance": "cosine"
  },
  "moduleConfig": {
    "img2vec-neural": {
      "imageFields": ["image"]
    }
  },
  "properties": [
    {
      "name": "image",
      "dataType": ["blob"]
    }
  ]
}

Fetch the database schema to retrieve all of the collection definitions.

Python
response = client.collections.list_all(simple=False)

print(response)
JavaScript/TypeScript
const allCollections = await client.collections.listAll()
console.log(JSON.stringify(allCollections, null, 2));
Go
schema, err := client.Schema().Getter().
  Do(ctx)
Java
List<CollectionConfig> response = client.collections.list();

System.out.println(response);
C#
var response = new List<CollectionConfig>();
await foreach (var collection in client.Collections.List())
{
    response.Add(collection);
    Console.WriteLine(collection);
}

You can update a collection definition to change the mutable collection settings.

Python
from weaviate.classes.config import (
    Reconfigure,
    VectorFilterStrategy,
    ReplicationDeletionStrategy,
)

articles = client.collections.use("Article")

# Update the collection definition
articles.config.update(
    description="An updated collection description.",
    property_descriptions={
        "title": "The updated title description for article",
    },  # Available from Weaviate v1.31.0
    inverted_index_config=Reconfigure.inverted_index(bm25_k1=1.5),
    vector_config=Reconfigure.Vectors.update(
        name="default",
        vector_index_config=Reconfigure.VectorIndex.hnsw(
            filter_strategy=VectorFilterStrategy.ACORN  # Available from Weaviate v1.27.0
        ),
    ),
    replication_config=Reconfigure.replication(
        deletion_strategy=ReplicationDeletionStrategy.TIME_BASED_RESOLUTION  # Available from Weaviate v1.28.0
    ),
)
JavaScript/TypeScript
import { reconfigure } from 'weaviate-client';
Go
updatedArticleClassConfig := &models.Class{
  // Note: The new collection config must be provided in full,
  // including the configuration that is not being updated.
  // We suggest using the original class config as a starting point.
  Class: "Article",
  InvertedIndexConfig: &models.InvertedIndexConfig{
    Bm25: &models.BM25Config{
      K1: 1.5,
    },
  },
  VectorIndexConfig: map[string]interface{}{
    "filterStrategy": "acorn",
  },
  ReplicationConfig: &models.ReplicationConfig{
    DeletionStrategy: models.ReplicationConfigDeletionStrategyTimeBasedResolution,
  },
}
Java
CollectionHandle<Map<String, Object>> articles =
    client.collections.use("Article");

articles.config.update(col -> col
    .description("An updated collection description.")
    .invertedIndex(idx -> idx.bm25(bm25Builder -> bm25Builder.k1(1.5f))));
C#
var articles = client.Collections.Use("Article");

await articles.Config.Update(c =>
{
    c.Description = "An updated collection description.";
    c.InvertedIndexConfig.Bm25.K1 = 1.5f;
});

You can delete any unwanted collection(s), along with the data that they contain.

This code deletes a collection and its objects.

{/*

GraphQL

*/}

Python
# collection_name can be a string ("Article") or a list of strings (["Article", "Category"])
client.collections.delete(
    collection_name
)  # THIS WILL DELETE THE SPECIFIED COLLECTION(S) AND THEIR OBJECTS

# Note: you can also delete all collections in the Weaviate instance with:
# client.collections.delete_all()
TypeScript
// delete collection "Article" - THIS WILL DELETE THE COLLECTION AND ALL ITS DATA
await client.collections.delete('Article')

// you can also delete all collections of a cluster
// await client.collections.deleteAll()
Go
className := "YourClassName"

// delete the class
if err := client.Schema().ClassDeleter().WithClassName(className).Do(context.Background()); err != nil {
  // Weaviate will return a 400 if the class does not exist, so this is allowed, only return an error if it's not a 400
  if status, ok := err.(*fault.WeaviateClientError); ok && status.StatusCode != http.StatusBadRequest {
    panic(err)
  }
}
Java
client.collections.delete(collectionName);
Bash
curl \
  -X DELETE \
  https://WEAVIATE_INSTANCE_URL/v1/schema/YourClassName  # Replace WEAVIATE_INSTANCE_URL with your instance URL
C#
await client.Collections.Delete(collectionName);
Indexing limitations after data import

There are no index limitations when you add collection properties before you import data.

If you add a new property after you import data, there is an impact on indexing.

Property indexes are built at import time. If you add a new property after importing some data, pre-existing objects index aren't automatically updated to add the new property. This means pre-existing objects aren't added to the new property index. Queries may return unexpected results because the index only includes new objects.

To create an index that includes all of the objects in a collection, do one of the following:

  • New collections: Add all of the collection's properties before importing objects.
  • Existing collections: Export the existing data from the collection. Re-create it with the new property. Import the data into the updated collection.

We are working on a re-indexing API to allow you to re-index the data after adding a property. This will be available in a future release.

Python
from weaviate.classes.config import Property, DataType

articles = client.collections.use("Article")

articles.config.add_property(Property(name="onHomepage", data_type=DataType.BOOL))
JavaScript/TypeScript
let articles = client.collections.use('Article')articles.config.addProperty({  name: "onHomepage",  dataType: "boolean",});
Go
package main

import (
  "context"

  "github.com/weaviate/weaviate-go-client/v5/weaviate"
  "github.com/weaviate/weaviate/entities/models"
)

func main() {
  cfg := weaviate.Config{
    Host:   "localhost:8080",
    Scheme: "http",
  }
  client, err := weaviate.NewClient(cfg)
  if err != nil {
    panic(err)
  }

  prop := &models.Property{
    DataType: []string{"boolean"},
    Name:     "onHomepage",
  }

  err := client.Schema().PropertyCreator().
    WithClassName("Article").
    WithProperty(prop).
    Do(context.Background())

  if err != nil {
    panic(err)
  }
}
Java
CollectionHandle<Map<String, Object>> articles =
    client.collections.use("Article");

articles.config.addProperty(Property.bool("onHomepage"));
C#
CollectionClient articles = client.Collections.Use("Article");
await articles.Config.AddProperty(Property.Text("description"));

Have a question or feedback? Here's how to reach us.

Suggest an edit

Propose a replacement for this page. The site team reviews it before applying any changes.

Export
Documentation menu