Pre-filtering Vector Searches

  • Capella Operational
  • how-to
March 23, 2025
+ 12
You can specify filters as part of a Vector Search query object to restrict the documents searched in a Search index.

About Pre-filtering

Using pre-filtering as part of your vector search offers two key advantages:

  1. Enhanced precision and relevance: Narrow your search results based on specific criteria, such as organization, date/time ranges, or geospatial locations.

  2. Performance optimization: Reduce the search space before executing queries to improve query execution time and reduce computational overhead.

Prerequisites

Procedure

To add pre-filtering to a Vector Search query:

  1. On the Operational Clusters page, select the operational cluster where you created your Search index.

  2. Go to Data Tools  Search.

  3. Next to your Vector Search index, click Search.

  4. In the Search field, enter a search query that includes a filter object with your knn object.

    For more information about the filter object, see filter.

  5. Press Enter or click Search.

  6. (Optional) To view a document and its source collection, click a document name in the search results list.

Example: Pre-Filter A Vector Search Query For The Color "Navy"

For example, the following Vector Search query tries to find matches to a color with an RGB value of [176, 0, 176] with a minimum brightness of 70 and a maximum of 80. A pre-filter on the query will narrow the documents searched inside the Vector Search index to documents that have a color field value that closely matches navy:

{
  "fields": ["*"],
  "query": {
    "min": 70,
    "max": 80,
    "inclusive_min": false,
    "inclusive_max": true,
    "field": "brightness"
  },
  "knn": [
    {
      "k": 10,
      "field": "colorvect_l2",
      "vector": [ 176, 0, 176 ],
      "filter": {
        "field":  "color",
        "match": "navy"
      }
    }
  ]
}