Skip to main content

Get

Retrieves, decrypts and returns items from their IDs. If an item does not exist at that ID, it will return an empty object.
def get(self,
        ids: List[str],
        include: List[str] = ["vector", "contents", "metadata"])

Parameters

ParameterTypeDefaultDescription
idsList[str]-Item IDs to retrieve & decrypt
includeList[str]"vector", "contents", "metadata"(Optional) List of item fields to return. Can include vector, contents, and metadata (vector only for IVFFlat indexes).

Returns

List[Dict]: Decrypted item fields for each item, including id and specified fields (e.g., vector, contents, and metadata).

Exceptions

  • Throws if the item could not be retrieved or decrypted.

Example Usage

# Load index
index = client.load_index(index_name=index_name, index_key=index_key)

# Retrieve the items using their IDs
items = index.get(["item_1", "item_2"])

print(items)
# Example output:
# [{"id": "item_1", "vector": [0.1, 0.2], "contents": "Example contents...", "metadata": {"type": "txt"}},
#  {"id": "item_2", "vector": [0.3, 0.4], "contents": "Example contents...", "metadata": {"type": "md"}},

# Retrieve only the item contents
items = index.get(["item_1", "item_2"], include=["contents"])
print(items)
# Example output:
# [{"id": "item_1", "contents": "Example contents..."},
#  {"id": "item_2", "contents": "Example contents..."}]
I