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.
- JavaScript
- Python
const results = await client.query({
databaseId,
query: {
key: 'job#1'
},
maxResults: 3,
});
console.log(results);
results = await client.query(QueryInput(
database_id=databaseId,
query=QueryTypeKey("job#1"),
max_results=3
))
print(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]
:
- JavaScript
- Python
const results = await client.query({
databaseId,
query: {
vector: [0.5, 0.5, 0.5, 0.5]
},
maxResults: 3,
});
console.log(results);
results = await client.query(QueryInput(
database_id=databaseId,
query=QueryTypeVector([0.5, 0.5, 0.5, 0.5]),
max_results=3
))
print(results)