Commands

Resumable Query

The resumableQuery method allows you to perform queries that can be resumed to fetch additional results. This is particularly useful for large result sets or when implementing pagination.

The dimension of the query vector must match the dimension of your index.

The score returned from query requests is a normalized value between 0 and 1, where 1 indicates the highest similarity and 0 the lowest regardless of the similarity function used.

Arguments

PayloadResumableQueryPayloadrequired

Response

ResumableQueryResponseObjectrequired
QueryResultObjectrequired
with Vector
const { result, fetchNext, stop } = await index.resumableQuery({  maxIdle: 3600,  topK: 50,  vector: [0, 1, 2, ..., 383], // 384-dimensional vector  includeMetadata: true,  includeVectors: true,});console.log(result);/*[  {    id: '6345',    score: 1.00000012,    vector: [0, 1, 2, ..., 383],    metadata: {      sentence: "Upstash is great."    }  },  // ... more results]*/const nextBatch = await fetchNext(5); // Fetch next 5 resultsconsole.log(nextBatch);await stop(); // Stop the resumable query
with Data
const { result, fetchNext, stop } = await index.resumableQuery({  maxIdle: 3600,  topK: 50,  data: "lord of the rings"  includeMetadata: true,  includeData: true,});console.log(result);/*[  {    id: '6345',    score: 1.00000012,    data: "hobbit",    metadata: {      sentence: "Upstash is great."    }  },  // ... more results]*/const nextBatch = await fetchNext(5); // Fetch next 5 resultsconsole.log(nextBatch);await stop(); // Stop the resumable query
with Metadata Type
type Metadata = {  title: string,  genre: 'sci-fi' | 'fantasy' | 'horror' | 'action'}const { result, fetchNext, stop } = await index.resumableQuery<Metadata>({  vector: [    ... // query embedding  ],  includeMetadata: true,  topK: 1,  filter: "genre = 'fantasy' and title = 'Lord of the Rings'",  maxIdle: 3600,})if (result[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 } = result[0].metadata;  console.log(`The best match in fantasy was ${title}`)}await stop();
Loading search…