The dimension of the query vector must match the dimension of your index.
Arguments
QueryOptions
required
Response
Vector[]
required
Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
await index.query({ topK: 2, vector: [ ... ]})
/*
{
matches: [
{
id: '6345',
score: 1.00000012,
vector: [],
metadata: {
sentence: "Upstash is great."
}
},
{
id: '1233',
score: 1.00000012,
vector: [],
metadata: undefined
},
],
namespace: ''
}
*/
type Metadata = {
title: string,
genre: 'sci-fi' | 'fantasy' | 'horror' | 'action'
}
const results = await index.query<Metadata>({
vector: [
... // query embedding
],
includeVectors: true,
topK: 1,
})
if (results[0].metadata) {
// Since we passed the Metadata type parameter above,
// we can interact with metadata fields without having to
// do any typecasting.
const { title, genre } = results[0].metadata;
console.log(`The best match in fantasy was ${title}`)
}
Hide child attributes
topK vectors will be returned.true would be the best practice, since it will make it easier to
identify the vectors.Hide child attributes
await index.query({ topK: 2, vector: [ ... ]})
/*
{
matches: [
{
id: '6345',
score: 1.00000012,
vector: [],
metadata: {
sentence: "Upstash is great."
}
},
{
id: '1233',
score: 1.00000012,
vector: [],
metadata: undefined
},
],
namespace: ''
}
*/
type Metadata = {
title: string,
genre: 'sci-fi' | 'fantasy' | 'horror' | 'action'
}
const results = await index.query<Metadata>({
vector: [
... // query embedding
],
includeVectors: true,
topK: 1,
})
if (results[0].metadata) {
// Since we passed the Metadata type parameter above,
// we can interact with metadata fields without having to
// do any typecasting.
const { title, genre } = results[0].metadata;
console.log(`The best match in fantasy was ${title}`)
}
Was this page helpful?