QueryResponse
Contains vector search results.
For the list of response object types, see Response Objects.
Use QueryResponse to inspect search result items and to access results through list-style indexing.
Attributes
| Attribute | Type | Description |
|---|---|---|
items |
list of QueryResultItem | Search results returned by the query. |
results |
list of QueryResultItem | Compatibility property that returns the same list as items. |
QueryResultItem
Represents one search hit returned in the items list of a QueryResponse.
Attributes
| Attribute | Type | Description |
|---|---|---|
id |
str or None |
Identifier of the matching record. |
metadata |
dict[str, Any] or None |
Metadata returned for the matching record. |
vector |
list[float or int] or None |
Vector returned for the matching record. |
distance |
int, float, or None |
Distance between the query and the matching record. |
Iterate Items
Iterate over response.items to inspect each search hit.
response = client.query(
table_name="product_vectors",
query_by={"vector": [0.12, 0.45, 0.32]},
top_k=3,
)
for item in response.items:
print(item.id, item.distance)
print(item.metadata)
Methods
| Method | Return Type | Description |
|---|---|---|
len(response) |
int |
Returns the number of query result items. |
response[index] |
QueryResultItem |
Returns the query result item at the specified zero-based index. |
model_dump() |
dict[str, Any] |
Returns a Pydantic dictionary representation of the object. |
model_dump_json() |
str |
Returns a Pydantic JSON string representation of the object. |
to_dict() |
dict[str, Any] |
Returns a dictionary representation compatible with earlier SDK response handling. |
to_json() |
str |
Returns a JSON string representation compatible with earlier SDK response handling. |
to_str() |
str |
Returns a readable string representation compatible with earlier SDK response handling. |
Iterate Attributes
Use serialization helpers to iterate response attributes and item attributes.
response = client.query(
table_name="product_vectors",
query_by={"vector": [0.12, 0.45, 0.32]},
top_k=3,
)
payload = response.to_dict()
for attribute, value in payload.items():
print(attribute, value)
for item in response.items:
item_payload = item.to_dict()
for attribute, value in item_payload.items():
print(attribute, value)
Sample Response
{
"items": [
{
"id": "prod_001",
"metadata": {
"name": "Trail running shoes",
"category": "footwear"
},
"distance": 0.00393
}
]
}
Returned By
Returned by: query().