Skip to main content
A search query, or query, is a request for information about data in AIMP indexes. AIMP supports several search methods:
  • Search for exact values: search for exact values or ranges of numbers, dates, IPs, or strings.
  • Full-text search: use full text queries to query unstructured textual data and find documents that best match query terms.
  • Vector search: store vectors in AIMP and use approximate nearest neighbor (ANN) to find vectors that are similar, supporting use cases like semantic search.
Common parameters for the request body of a query are as follows:
Depending on your data and your query, you may get fewer than size results. This happens when size is larger than the number of possible matching documents for your query.
AIMP is eventually consistent, so there can be a slight delay before new or changed documents are visible to queries. If your application requires strongly consistent read, set consistentRead to true when query your data, at the expense of potential high latency and cost.
Query results are returned in the following format: Example query request to AIMP is as follows:
python
The response will look like this:
Matched documents are ordered by similarity from most similar to least similar by default. Similarity is expressed as a score, and it is calculated based on BM25 algorithm for full-text search and a configured similarity metric for vector search.

Query string query

AIMP supports a simple query string query that uses the Lucene Query Syntax to search documents. Specifically, term, phrase, wildcard, boolean operators, range operators, and special character escaping are supported. A query to an index with object field type requires special handling. An example index mappings:
An example query:

Vector query

A k-nearest neighbor (kNN) search finds the k nearest vectors to a query vector, as measured by a similarity metric. An example vector query:
Higher numCandidates likely leads to higher recall but also higher resource usage.
An example vector query with a filter for better performance:

Boolean query

A query that matches documents matching boolean combinations of other queries. The boolean query maps to Lucene BooleanQuery. It is built using one or more boolean clauses, each clause with a typed occurrence. The occurrence types are: Below is an example of a boolean query:
This query will return top documents that are both of type NODE and have the highest score value.
occur parameter is optional and defaults to should.

Boost query

Boost values that are less than one will give less importance to this query compared to other ones while values that are greater than one will give more importance to the scores returned by this query.
The boost value must be greater than zero.
The final score of the matched document is calculated as proportional to the boost values.

Hybrid query

You can mix the aforementioned queries with a vector query to get better relavance. An example hybrid query:
To explain the above example, it works as follows: A total of two queries are combined into a bool query, performing a hybrid query that combines a queryString and a knn. The score of documents matching in the queryString is boosted by 0.7 during the calculation. In the knn, a pre-filtering is performed using a filter, followed by a vector query that calculates the scores of the top 5 most similar documents with a boost of 0.3.
The final returned documents may not include the requested number of documents from the knn query. This is because the scores of documents returned solely from the queryString may be higher than those of the top 5 documents returned from the knn. If you want to ensure that documents from the knn are included, you should modify the occurrence of the knn to must.

Sort search results

AIMP allows you to add one or more sorts on specific fields. Each sort can be reversed as well. The sort is defined on a per field level.
Sorting can be done on the following data types:
  • long
  • double
  • datetime
The sort order option can have the following values:
  • asc: sorts in ascending order
  • desc: sorts in descending order
Assuming the following index mapping:
You can sort search results as follows:
When sorting on a field, scores are not computed. By setting trackScores to true, scores will still be computed and tracked.

Query limits

The query result size is affected by the dimension of the vectors and whether vector values are included in the result.
If a query fails due to exceeding the 6MB result size limit, choose a lower size value, or includeVectors=false to exclude vector values from the result.