Install an SDK
The Shaped SDK simplifies interactions with Shaped's V2 Query API, making it easier to integrate our services into your applications.
This guide will walk you through the installation process for different programming languages.
Install the SDK
- JavaScript
- Python
Install
npm install @shaped.ai/client
Install
pip install shaped
Verify Installation
Use the following commands to verify the packages have installed correctly.
- JavaScript
- Python
npm list @shaped.ai/client
pip show shaped
Making Queries
The V2 Query API uses ShapedQL (SQL) to retrieve and rank items. Here's how to make queries using the REST API:
- JavaScript
- Python
// Get personalized recommendations for a user.
const response = await fetch("https://api.shaped.ai/v2/engines/your_engine_name/query", {
method: "POST",
headers: {
"Content-Type": "application/json",
"x-api-key": "your_api_key"
},
body: JSON.stringify({
query: "SELECT * FROM similarity(embedding_ref='als', limit=100, encoder='interaction_pooling', input_user_id=$user_id) LIMIT 20",
parameters: {
user_id: "user123"
},
return_metadata: true
})
})
const recommendations = await response.json()
// Get items with filtering.
const response = await fetch("https://api.shaped.ai/v2/engines/your_engine_name/query", {
method: "POST",
headers: {
"Content-Type": "application/json",
"x-api-key": "your_api_key"
},
body: JSON.stringify({
query: "SELECT * FROM similarity(embedding_ref='als', limit=100, encoder='interaction_pooling', input_user_id=$user_id) WHERE category = 'sports' AND price < 100 LIMIT 20",
parameters: {
user_id: "user123"
},
return_metadata: true
})
})
// Execute a saved query.
const response = await fetch("https://api.shaped.ai/v2/engines/your_engine_name/queries/get_recommended_items", {
method: "POST",
headers: {
"Content-Type": "application/json",
"x-api-key": "your_api_key"
},
body: JSON.stringify({
parameters: {
user_id: "user123"
}
})
})
const recommendations = await response.json()
import requests
# Get personalized recommendations for a user.
response = requests.post(
"https://api.shaped.ai/v2/engines/your_engine_name/query",
headers={
"Content-Type": "application/json",
"x-api-key": "your_api_key"
},
json={
"query": "SELECT * FROM similarity(embedding_ref='als', limit=100, encoder='interaction_pooling', input_user_id=$user_id) LIMIT 20",
"parameters": {
"user_id": "user123"
},
"return_metadata": True
}
)
recommendations = response.json()
# Get items with filtering.
response = requests.post(
"https://api.shaped.ai/v2/engines/your_engine_name/query",
headers={
"Content-Type": "application/json",
"x-api-key": "your_api_key"
},
json={
"query": "SELECT * FROM similarity(embedding_ref='als', limit=100, encoder='interaction_pooling', input_user_id=$user_id) WHERE category = 'sports' AND price < 100 LIMIT 20",
"parameters": {
"user_id": "user123"
},
"return_metadata": True
}
)
# Execute a saved query.
response = requests.post(
"https://api.shaped.ai/v2/engines/your_engine_name/queries/get_recommended_items",
headers={
"Content-Type": "application/json",
"x-api-key": "your_api_key"
},
json={
"parameters": {
"user_id": "user123"
}
}
)
recommendations = response.json()
For more query examples and ShapedQL syntax, see the Query Reference.