Features
Metadata
Metadata feature allows you to store context with your vectors to make a connection. There can be a couple of uses of this:
- You can put the source of the vector in the metadata to use in your application from the query response.
- You can put some metadata to further filter the results upon the query.
You can set metadata with your vector as follows:
from upstash_vector import Index
index = Index(
url="UPSTASH_VECTOR_REST_URL",
token="UPSTASH_VECTOR_REST_TOKEN",
)
index.upsert(
[("id-0", [0.9215, 0.3897]), {"url": "https://imgur.com/z9AVZLb"}],
)
When you do a query or fetch, you can opt-in to retrieve the metadata as follows:
- Query Example
from upstash_vector import Index
index = Index(
url="UPSTASH_VECTOR_REST_URL",
token="UPSTASH_VECTOR_REST_TOKEN",
)
index.query(
[0.9215, 0.3897],
top_k=5,
include_metadata=True,
)
{
"result": [
{
"id": "id-0",
"score": 1,
"metadata": {
"url": "https://imgur.com/z9AVZLb"
}
},
{
"id": "id-3",
"score": 0.99961007,
"metadata": {
"url": "https://imgur.com/zfOPmnI"
}
}
]
}
Also, you can filter the results further by providing a metadata filter:
from upstash_vector import Index
index = Index(
url="UPSTASH_VECTOR_REST_URL",
token="UPSTASH_VECTOR_REST_TOKEN",
)
index.query(
[0.9215, 0.3897],
top_k=5,
include_metadata=True,
filter="url GLOB '*imgur.com*'",
)
See Metadata Filtering documentation for more details.
- Range Example
from upstash_vector import Index
index = Index(
url="UPSTASH_VECTOR_REST_URL",
token="UPSTASH_VECTOR_REST_TOKEN",
)
index.range(
cursor="0",
limit=3,
include_metadata=True,
)
{
"result": {
"nextCursor": "4",
"vectors": [
{ "id": "id-0", "metadata": { "url": "https://imgur.com/z9AVZLb" } },
{ "id": "id-1", "metadata": { "url": "https://imgur.com/a2nCEIt" } },
{ "id": "id-2", "metadata": { "url": "https://imgur.com/zfOPmnI" } }
]
}
}
Was this page helpful?