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:

# Note - The V4 Python client uses gRPC for object-related operations.
# The snippets shown are for the same functionality as the REST call.

import weaviate

client = weaviate.connect_to_local()

try:
object_uuid = generate_uuid5("SomeUUIDSeed")

authors = client.collections.get("Author")
# authors = authors.with_consistency_level(wvc.config.ConsistencyLevel.ALL) # If you want to set the consistency level

fetched_obj = authors.query.fetch_object_by_id(uuid=object_uuid) # If it does not exist, it will return None

if fetched_obj is None:
print("Object does not exist")
else:
print(fetched_obj.properties)

finally:
client.close()

Questions and feedback

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