By specifying a Boolean expression, users can filter the scalar field of the entities during the vector search. Hippo will only return the results that match the filter condition. Scalar field indexing is an excellent way of improving the performance and accuracy rate of hybrid search.
curl -u shiva:shiva -XGET 'localhost:8902/hippo/v1/{table}/_search?pretty' -H 'Content-Type: application/json' -d'{
"output_fields": ["book_id"],
"search_params": {
"anns_field": "book_intro",
"topk": 2,
"params": {
"k_factor" : 100
}
},
"vectors": [ [0.1,0.2], [0.3, 0.4] ],
"dsl": "word_count >= 11000",
"only_explain" : false
}';
Result:
{
"num_queries" : 2,
"top_k" : 2,
"results" : [
{
"query" : 0,
"fields_data" : [
{
"field_name" : "book_id",
"field_values" : [11,12]
}
],
"scores" : [119.44999,142.24998]
},
{
"query" : 1,
"fields_data" : [
{
"field_name" : "book_id",
"field_values" : [11,12]
}
],
"scores" : [114.85,137.25]
}
]
}
Parameter description:
Parameters | Description | Required |
---|---|---|
table | Table name, such as "book" created in this example | Yes |
database_name | Database where the table is located | No, defaults to "default" database |
output_fields | Name of the field to return | Yes |
anns_field | Name of the field to search on | Yes |
topk | The number of records to return | Yes |
params | Search parameter specific to vector index | No |
embedding_index | Vector index used in current search | No, uses the first activated vector index built on the field specified in "anns_field" by default |
vectors | Query vector | Yes |
dsl | Scalar filter condition | Yes |
only_explain | Whether to execute "explain" only | No, defaults to false |
Hybrid Search Using Array and Vector Fields
This chapter introduces how to conduct hybrid search using indexed array and vector fields. Regarding how to create array index, please refer to Create Array Index.
curl -u shiva:shiva -XGET 'localhost:8902/hippo/v1/book/_search?database_name={database_name}&pretty' -H'Content-Type: application/json' -d'{
"output_fields": ["book_id"],
"search_params": {
"anns_field": "book_intro",
"topk": 10
},
"vectors": [ [0.1,0.2], [0.3, 0.4] ],
"dsl": "attributes in [attr5, attr8, attr9]"
}';
Result:
{
"num_queries" : 2,
"top_k" : 10,
"results" : [
{
"query" : 0,
"fields_data" : [
{
"field_name" : "book_id",
"field_values" : [21,22,23,24,25,26,27,28,29,30],
"scores" : [437.45,480.25,525.05,571.85,620.65,671.45,724.25,779.05,835.85,894.64996]
}
]
},
{
"query" : 1,
"fields_data" : [
{
"field_name" : "book_id",
"field_values" : [21,22,23,24,25,26,27,28,29,30],
"scores" : [428.85,471.25003,515.65,562.05005,610.45,660.85004,713.25,767.65,824.05005,882.45]
}
]
}
]
}