Skip to main content

Step 5: Basic queries

In this step, we will query data using only the vector field. We will query for the 3 closest documents to a given vector.

Querying an item's neighbours

To query for an item's neighbours, we can specify the key of the item we want to query. This will return the closest items to the item with the specified key.

const results = await client.query({
databaseId,
query: {
key: 'job#1'
},
maxResults: 3,
});

console.log(results);

Querying by vector

To query for items closest to a given vector, we can specify the vector we want to query. In this example, we will query for the 3 closest items to the vector [0.5, 0.5, 0.5, 0.5]:

  const results = await client.query({
databaseId,
query: {
vector: [0.5, 0.5, 0.5, 0.5]
},
maxResults: 3,
});

console.log(results);