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 schema objects for both semantic types (i.e., things and actions).

Method and URL

GET /v1/schema

Example request

  import weaviate

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

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

Example response

 {
   "actions": {
     "classes": [],
     "type": "action"
   },
   "things": {
     "classes": [{
       "class": "Publication",
       "description": "A publication with an online source",
       "properties": [
         {
           "dataType": [
             "string"
           ],
           "description": "Name of the publication",
           "name": "name"
         },
         {
           "dataType": [
             "Article"
           ],
           "description": "The articles this publication has",
           "name": "hasArticles"
         },
         {
           "dataType": [
               "geoCoordinates"
           ],
           "description": "Geo location of the HQ",
           "name": "headquartersGeoLocation"
         }
       ]
     }, {
       "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"
         }
       ]
     }, {
       "class": "Author",
       "description": "The writer of an article",
       "properties": [
         {
           "dataType": [
               "string"
           ],
           "description": "Name of the author",
           "name": "name"
         },
         {
           "dataType": [
               "Article"
           ],
           "description": "Articles this author wrote",
           "name": "wroteArticles"
         },
         {
           "dataType": [
               "Publication"
           ],
           "description": "The publication this author writes for",
           "name": "writesFor"
         }
       ]
     }],
   "type": "thing"
   }
 }

Create a class

Create a new semantic kind (i.e., things or actions) class in the schema.

Method and URL

POST /v1/schema/{semantic_kind}

Parameters

namelocationtypedescription
{semantic_kind}URLstringA semantic kind is used to -respectively- describe nouns or verbs. Options are things or actions
classbodystringThe name of the class, multiple words should be concatenated in CamelCase like ArticleAuthor.
vectorizeClassNamebodybooleanShould the classname be part of the vector index? Learn more about how to regulate indexing in Weaviate here.
descriptionbodystringDescription of the classname
propertiesbodyarrayAn array of property objects
properties > dataTypebodyarrayClick here for a list of available data types.
properties > descriptionbodystringDescription of the property
properties > vectorizePropertyNamebodybooleanShould the property be part of the vector index? 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 > indexbodybooleanShould the the data stored in this property be indexed? Learn more about how to regulate indexing in Weaviate here.

Example request for creating a Thing

  import weaviate

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

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

new_class = client.schema.create_class(class_obj)

Example request for creating an Action

  import weaviate
from weaviate import SEMANTIC_TYPE_ACTIONS

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

class_obj = {
    "class": "Publish",
    "description": "Making a new article available",
    "vectorizeClassName": True,
    "properties": [
        {
        "dataType": [
            "date"
        ],
        "description": "The date of when the article came online",
        "name": "publicationDate",
        "vectorizePropertyName": True,
        "index": True
        },
        {
        "dataType": [
            "Publication"
        ],
        "description": "Which publication published the article",
        "name": "publisher"
        },
        {
        "dataType": [
            "Article"
        ],
        "description": "The article that was published",
        "name": "article"
        }
    ]
}

new_class = client.schema.create_class(class_obj, SEMANTIC_TYPE_ACTIONS)

Delete a class

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

Method and URL

DELETE v1/schema/{semantic_kind}/{class_name}

Parameters

namelocationtypedescription
{semantic_kind}URLstringA semantic kind is used to -respectively- describe nouns or verbs. Options are things or actions
{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/{semantic_kind}/{class_name}/properties

Parameters

namelocationtypedescription
{semantic_kind}URLstringA semantic kind is used to -respectively- describe nouns or verbs. Options are things or actions
{class_name}URLstringThe name of the class
dataTypebodyarrayClick here for a list of available data types.
descriptionbodystringDescription of the property
vectorizePropertyNamebodybooleanShould the proename be part of the vector index? Learn more about how to regulate indexing in Weaviate here
namebodystringThe name of the property, multiple words should be concatenated in camelCase like nameOfAuthor.
indexbodybooleanShould 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