Search
Search queries allow you to find items based on a text query. Shaped supports three search modes:
- Hybrid search - combines semantic and lexical signals
- Semantic search - finds items by meaning using vector embeddings
- Lexical search - finds items by exact keyword matching
Hybrid search
Hybrid search combines multiple retrieval strategies to return a blended list of results. Use hybrid search when you need to balance semantic understanding and exact keyword matching.
Prerequisites
- An engine with a text embedding configured for vector search
- Lexical search configured on searchable text fields
- A search query text
Query example
This example retrieves candidates from two sources (vector search and lexical search), then returns the blended results:
{
"query": {
"type": "rank",
"from": "item",
"retrieve": [
{
"type": "text_search",
"input_text_query": "$parameters.query_text",
"mode": { "type": "vector", "text_embedding_ref": "text_embedding" },
"limit": 50
},
{
"type": "text_search",
"input_text_query": "$parameters.query_text",
"mode": { "type": "lexical", "fuzziness_edit_distance": 2 },
"limit": 50
}
],
"limit": 20
},
"parameters": {
"query_text": "Blue shirt"
}
}
Tuning the blend
You can adjust the limit on each retriever to control the balance between semantic and lexical results. A higher limit on one retriever will give it more influence on the final results.
Semantic search
Semantic search uses vector embeddings to find items that are semantically similar to the query text, even if they don't contain the exact keywords.
Prerequisites
- An engine with a text embedding configured
- A search query text
Query example
{
"query": {
"type": "rank",
"from": "item",
"retrieve": [
{
"type": "text_search",
"input_text_query": "$parameters.query_text",
"mode": { "type": "vector", "text_embedding_ref": "text_embedding" },
"limit": 20
}
]
},
"parameters": {
"query_text": "Blue shirt"
}
}
Lexical search
Lexical search finds items that contain the exact keywords from the query, with optional fuzzy matching for typos.
Prerequisites
- Lexical search configured on searchable text fields
- A search query text
Query example
{
"query": {
"type": "rank",
"from": "item",
"retrieve": [
{
"type": "text_search",
"input_text_query": "$parameters.query_text",
"mode": { "type": "lexical", "fuzziness_edit_distance": 2 },
"limit": 20
}
]
},
"parameters": {
"query_text": "Blue shirt"
}
}