Skip to main content

Read objects

Instead of querying your database, you can use an ID to retrieve individual objects.

Additional information
Collection (class) Name in Object CRUD Operations

Collections act like namespaces, so two different collections could have duplicate IDs between them.


Prior to Weaviate v1.14 you can manipulate objects without specifying the collection name. This method is deprecated. It will be removed in Weaviate v2.0.0.

Starting in v1.20, you can have multi-tenant datasets. When multi-tenancy is enabled, the tenant name is required.

Always include the collection name, and, when enabled, the tenant name.

Get an object by id

Use an ID to retrieve an object. If the id doesn't exist, Weaviate returns a 404 error.

jeopardy = client.collections.get("JeopardyQuestion")

data_object = jeopardy.query.fetch_object_by_id("00ff6900-e64f-5d94-90db-c8cfa3fc851b")

print(data_object.properties)

Retrieve the object's vector

Object vectors can be retrieved by specifying its return.

jeopardy = client.collections.get("JeopardyQuestion")

data_object = jeopardy.query.fetch_object_by_id(
"00ff6900-e64f-5d94-90db-c8cfa3fc851b",
include_vector=True
)

print(data_object.vector["default"])

Retrieve named vectors

Where named vectors are used, you can retrieve one or more of them by specifying their names.

reviews = client.collections.get("WineReviewNV")  # Collection with named vectors
vector_names = ["title", "review_body"]

data_object = reviews.query.fetch_object_by_id(
uuid=obj_uuid, # Object UUID
include_vector=vector_names # Specify names of the vectors to include
)

# The vectors are returned in the `vector` property as a dictionary
for n in vector_names:
print(f"Vector '{n}': {data_object.vector[n][:5]}...")

Check object existence

To efficiently check if an object with a given id exists without retrieving it, make a HEAD request to the /v1/objects/ REST endpoint, or use the following client code:

# generate uuid based on the key properties used during data insert
object_uuid = generate_uuid5({"name": "Author to fetch"})

authors = client.collections.get("Author")
author_exists = authors.data.exists(object_uuid)

print("Author exist: ", author_exists)

Questions and feedback

If you have any questions or feedback, let us know in the user forum.