Classification in Weaviate refers to assigning a predefined label or category to a given data instance based on its inherent characteristics or features. It involves utilizing machine learning algorithms or statistical models to analyze the properties of the data and make accurate predictions about its class membership.
Weaviate's classification framework involves feature extraction, dimensionality reduction, and model training, where the system learns patterns and relationships within the data to generalize and classify new, unseen instances.
The resulting classifier can then classify incoming data instances based on their similarity to the learned patterns, enabling efficient and automated categorization in the Weaviate knowledge graph.
Weaviate Create Class
Let us start by creating a class to store film data. We will use this to demonstrate classification and gather data about the classification.
import weaviate
import json
client = weaviate.Client("http://localhost:8080")
class_obj = {
"class": "Film",
"description": "A class representing a film.",
"vectorIndexType": "hnsw",
"vectorIndexConfig": {
"distance": "cosine",
"efConstruction": 128,
"maxConnections": 32
},
"properties": [
{
"name": "title",
"dataType": ["string"],
"description": "The title of the film."
},
{
"name": "director",
"dataType": ["string"],
"description": "The director of the film."
},
{
"name": "year",
"dataType": ["int"],
"description": "The year the film was released."
},
{
"name": "genre",
"dataType": ["string"],
"description": "The genre of the film."
},
{
"name": "actors",
"dataType": ["string"],
"description": "The actors in the film."
}
]
}
client.schema.create_class(class_obj)
schema = client.schema.get()
This should create a Film class with various properties.
Weaviate Start Classification.
Once we have the class and sample data, we can start a classificiation. For this post, we will use a KNN classification.
trainingSetWhere = {
"path": ["wordCount"],
"operator": "GreaterThan",
"valueInt": 1
}
This should start a KNN classification on the target class. Once you get the classification ID, use it to gather the details about the classification.
End.
In this post, we demonstrated the basics of working with the classification API in Weaviate to create a basic KNN classification. You can refer to the documentation for the various supported classifications and which one suits your data.