Table of documentation contents

/v1/schema

Before adding data to Weaviate, you need to create a schema. The schema contains the structure of your Weaviate in graph format. You will use the graph format to search through your Weaviate instance using GraphQL. To learn how to create a schema, you can follow this How-To tutorial.

Get the schema

Dumps the current Weaviate schema. The result contains an array of objects.

Method and URL

GET /v1/schema

Example request

  import weaviate

client = weaviate.Client("http://localhost:8080")

schema = client.schema.get()
print(schema)

Example response

{
  "classes": [
    {
      "class": "Category",
      "description": "Category an article is a type off",
      "moduleConfig": {
        "text2vec-contextionary": {
          "vectorizeClassName": false
        }
      },
      "properties": [
        {
          "dataType": [
            "string"
          ],
          "description": "category name",
          "indexInverted": true,
          "moduleConfig": {
            "text2vec-contextionary": {
              "vectorizePropertyName": false
            }
          },
          "name": "name"
        }
      ],
      "vectorIndexType": "hnsw",
      "vectorizer": "none"
    },
    {
      "class": "Publication",
      "description": "A publication with an online source",
      "moduleConfig": {
        "text2vec-contextionary": {
          "vectorizeClassName": false
        }
      },
      "properties": [
        {
          "dataType": [
            "string"
          ],
          "description": "Name of the publication",
          "name": "name"
        },
        {
          "dataType": [
            "geoCoordinates"
          ],
          "description": "Geo location of the HQ",
          "name": "headquartersGeoLocation"
        },
        {
          "dataType": [
            "Article"
          ],
          "description": "The articles this publication has",
          "name": "hasArticles"
        },
        {
          "dataType": [
            "Article"
          ],
          "description": "Articles this author wrote",
          "name": "wroteArticles"
        }
      ],
      "vectorIndexType": "hnsw",
      "vectorizer": "none"
    },
    {
      "class": "Author",
      "description": "Normalised types",
      "moduleConfig": {
        "text2vec-contextionary": {
          "vectorizeClassName": true
        }
      },
      "properties": [
        {
          "dataType": [
            "string"
          ],
          "description": "Name of the author",
          "name": "name"
        },
        {
          "dataType": [
            "Publication"
          ],
          "description": "The publication this author writes for",
          "name": "writesFor"
        }
      ],
      "vectorIndexType": "hnsw",
      "vectorizer": "none"
    },
    {
      "class": "Article",
      "description": "Normalised types",
      "moduleConfig": {
        "text2vec-contextionary": {
          "vectorizeClassName": false
        }
      },
      "properties": [
        {
          "dataType": [
            "string"
          ],
          "description": "title of the article",
          "indexInverted": true,
          "moduleConfig": {
            "text2vec-contextionary": {
              "vectorizePropertyName": false
            }
          },
          "name": "title"
        },
        {
          "dataType": [
            "string"
          ],
          "description": "url of the article",
          "indexInverted": false,
          "moduleConfig": {
            "text2vec-contextionary": {
              "vectorizePropertyName": false
            }
          },
          "name": "url"
        },
        {
          "dataType": [
            "text"
          ],
          "description": "summary of the article",
          "indexInverted": true,
          "moduleConfig": {
            "text2vec-contextionary": {
              "vectorizePropertyName": false
            }
          },
          "name": "summary"
        },
        {
          "dataType": [
            "date"
          ],
          "description": "date of publication of the article",
          "name": "publicationDate"
        },
        {
          "dataType": [
            "int"
          ],
          "description": "Words in this article",
          "name": "wordCount"
        },
        {
          "dataType": [
            "Author",
            "Publication"
          ],
          "description": "authors this article has",
          "name": "hasAuthors"
        },
        {
          "dataType": [
            "Publication"
          ],
          "description": "publication this article is in",
          "name": "inPublication"
        },
        {
          "dataType": [
            "Category"
          ],
          "description": "category this article is of",
          "name": "ofCategory"
        },
        {
          "dataType": [
            "boolean"
          ],
          "description": "whether the article is currently accessible through the url",
          "name": "isAccessible"
        }
      ],
      "vectorIndexType": "hnsw",
      "vectorizer": "none"
    }
  ]
}

Create a class

Create a new data object class in the schema.

Method and URL

POST /v1/schema

Parameters

Learn more about the schema configuration here.

namelocationtypedescription
classbodystringThe name of the class, multiple words should be concatenated in CamelCase like ArticleAuthor.
descriptionbodystringDescription of the classname
vectorIndexTypebodystringdefaults to hnsw, can be omitted in schema definition since this is the only available type for now
vectorIndexConfigbodyobjectvector index type specific settings
vectorizerbodystringvectorizer to use for data objects added to this class, default can be set in Weaviate’s environment variables
moduleConfig > text2vec-contextionary > vectorizeClassNamebodyobjectinclude the class name in vector calculation (default true). Learn more about how to regulate indexing in Weaviate here.
propertiesbodyarrayAn array of property objects
properties > dataTypebodyarrayClick here for a list of available data types.
properties > descriptionbodystringDescription of the property
properties > moduleConfig > text2vec-contextionary > skipbodybooleanif true, the whole property will be included in vectorization. default is false
properties > moduleConfig > text2vec-contextionary > vectorizePropertyNamebodybooleanwhether name of the property is used in the calculation for the vector position of data objects. default is true. Learn more about how to regulate indexing in Weaviate here.
properties > namebodystringThe name of the property, multiple words should be concatenated in camelCase like nameOfAuthor.
properties > indexInvertedbodybooleanShould the the data stored in this property be indexed? Learn more about how to regulate indexing in Weaviate here.

Example request for creating a class

  import weaviate

client = weaviate.Client("http://localhost:8080")

class_obj = {
    "class": "Article",
    "description": "A written text, for example a news article or blog post",
    "properties": [
        {
        "dataType": [
            "string"
        ],
        "description": "Title of the article",
        "name": "title",
        },
        {
        "dataType": [
            "text"
        ],
        "description": "The content of the article",
        "name": "content"
        }
    ]
}

new_class = client.schema.create_class(class_obj)

Or with all the possible parameters:

  import weaviate

client = weaviate.Client("http://localhost:8080")

class_obj = {
    "class": "Article",
    "description": "A written text, for example a news article or blog post",
    "vectorIndexType": "hnsw",
    "vectorIndexConfig": {
        "efConstruction": 128,
        "maxConnections": 64
    },
    "vectorizer": "text2vec-contextionary",
    "moduleConfig": {
      "text2vec-contextionary": {  
        "vectorizeClassName": True
      }
    },
    "properties": [
        {
            "dataType": [
                "string"
            ],
            "description": "Title of the article",
            "name": "title",
            "indexInverted": True,
            "moduleConfig": {
                "text2vec-contextionary": {
                  "skip": False,                   
                  "vectorizePropertyName": False
                }
              }
        },
        {
            "dataType": [
                "text"
            ],
            "description": "The content of the article",
            "name": "content",
            "indexInverted": True,
            "moduleConfig": {
                "text2vec-contextionary": {
                  "skip": False,                   
                  "vectorizePropertyName": False
                }
              }
        }
    ]
}

new_class = client.schema.create_class(class_obj)

Delete a class

Remove a class (and all data in the instances) from the schema.

Method and URL

DELETE v1/schema/{class_name}

Parameters

namelocationtypedescription
{class_name}URLstringThe name of the class

Example request for deleting a class

  import weaviate

client = weaviate.Client("http://localhost:8080")

client.schema.delete_class('Article')

Add a property

Method and URL

POST v1/schema/{class_name}/properties

Parameters

namelocationtypedescription
dataTypebodyarrayClick here for a list of available data types.
descriptionbodystringDescription of the property
moduleConfig > text2vec-contextionary > skipbodybooleanif true, the whole property will be included in vectorization. default is false
moduleConfig > text2vec-contextionary > vectorizePropertyNamebodybooleanwhether name of the property is used in the calculation for the vector position of data objects. default is true. Learn more about how to regulate indexing in Weaviate here.
namebodystringThe name of the property, multiple words should be concatenated in camelCase like nameOfAuthor.
indexInvertedbodybooleanShould the the data stored in this property be indexed? Learn more about how to regulate indexing in Weaviate here.

Example request for adding a property

  import weaviate

client = weaviate.Client("http://localhost:8080")

add_prop = {
  "dataType": [
      "boolean"
  ],
  "name": "onHomepage"
}

client.schema.property.create("Article", add_prop)

More Resources

If you can’t find the answer to your question here, please look at the:

  1. Frequently Asked Questions. Or,
  2. Knowledge base of old issues. Or,
  3. For questions: Stackoverflow. Or,
  4. For issues: Github. Or,
  5. Ask your question in the Slack channel: Slack.
Tags
  • RESTful API
  • references
  • schema