Make a query
info
This is a preview of the new Shaped docs. Found an issue or have feedback? Let us know!
Queries retrieve data from a Shaped engine. You can write ad-hoc queries to try different retrieval strategies at runtime, or run saved queries to standarize retrieval across your codebase. A query can do a single filter operation or run multiple retrievers in sequence.
Make an ad-hoc query
Ad-hoc queries are defined at runtime by the client.
- JavaScript
- Python
fetch("https://api.shaped.ai/v1/datasets/movies/query", {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({
query: {
type: "rank_items",
retrieve: {
name: "similar_items",
embedding_ref: "als",
type: "item_similarity",
query_encoder: {
input_item_id: "$param.item_id",
type: "item_attribute_pooling"
}
}
},
params: {
item_id: "db1234"
}
})
})
response = requests.post(
"https://api.shaped.ai/v1/datasets/movies/query",
json={
"query": {
"type": "rank_items",
"retrieve": {
"name": "similar_items",
"embedding_ref": "als",
"type": "item_similarity",
"query_encoder": {
"input_item_id": "$param.item_id",
"type": "item_attribute_pooling"
}
}
},
"params": {
"item_id": "db1234"
}
}
)
print(response.json())
Execute a saved query
Saved queries are declared on the engine level. They allow multiple clients (eg a mobile app and website) to execute the same queries against an engine.
- JavaScript
- Python
fetch("https://api.shaped.ai/v1/datasets/movies/queries/get_recommended_items", {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({
parameters: {
user_id: "db1234",
}
})
})
import requests
response = requests.post(
"https://api.shaped.ai/v1/datasets/movies/queries/get_recommended_items",
json={
"parameters": {
"user_id": "db1234"
}
}
)
print(response.json())