Pre-filtering Vector Searches

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

    About Pre-filtering

    The Search Service supports pre-filtering on Vector Search queries. Pre-filtering allows you to execute vector searches over a subset of the vector index, via the means of a filter request that qualifies the subset.

    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 Search Vector 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 Search Vector 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"
          }
        }
      ]
    }