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]}...")