AI

Get All Objects in Weaviate

Weaviate is an open-source knowledge graph and vector search engine developed by Semantria. It uses the machine learning techniques to organize and retrieve the data based on its semantic meaning.

Weaviate objects provide a structured way to represent and organize the data in a knowledge graph, enabling the advanced search and retrieval capabilities based on the semantic understanding of the information.

In this tutorial, we will learn how you can use the provided Weaviate features to list all objects within the Weaviate cluster.

List the Objects in Weaviate Using HTTP

The API endpoint is the most common way of fetching the objects in a Weaviate cluster. The following shows the HTTP method and URL to query the Weaviate objects:

GET /v1/objects

The request returns all the objects in all the Weaviate classes. However, the output is limited to 25 objects per output.

Query Parameters

You can also include the other parameters in the query which govern the operation of the query and the resulting output.

The parameters are as expressed in the following:

  • Class – List the objects by class using the class name.
  • Limit – The maximum number of data objects to return. The default number is 25.
  • Offset – The offset of returned objects (the starting index of the returned objects). It is use in conjunction with limit.
  • After – The ID of the object after which the objects are to be listed.
  • Include – It includes the additional information such as classification info. The allowed values include classification, vector, and featureProjection.
  • Sort – The name of the property to sort by – i.e., sort=city.
  • Order – The order in which to sort by. Possible values: asc (default) and desc.

An example usage of the previous query parameters is as follows:

GET /v1/objects?class={ClassName}&limit={limit}&include={include}

In this case, the previous query specifies the class name, limit, the information to include, and more.

You can also perform the paging of the objects using the limit and offset parameters as follows:

GET /v1/objects?class=ClassName&limit=10

This should return the first ten objects from the specified class. To fetch the next ten objects, you can use the offset parameter:

GET /v1/objects?class=MyClass&limit=10&offset=10

List the Objects in Weaviate Using Python

You can also use the Weaviate Python client to list all the objects in the Weaviate class as follows:

import weaviate

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

all_objects = client.data_object.get(class_name="ClassName")

print(all_objects)

This should return all the objects in the specified class.

Conclusion

We learned how to get a list of all the objects in various Weaviate classes including limiting the output, paging, and more. You can explore the docs to learn more.

About the author

John Otieno

My name is John and am a fellow geek like you. I am passionate about all things computers from Hardware, Operating systems to Programming. My dream is to share my knowledge with the world and help out fellow geeks. Follow my content by subscribing to LinuxHint mailing list