|
| 1 | += Pre-filtering Vector Searches |
| 2 | +:page-topic-type: guide |
| 3 | +:page-ui-name: {ui-name} |
| 4 | +:description: You can specify filters as part of a vector search statement which will restrict the documents searched during the query. |
| 5 | + |
| 6 | +[abstract] |
| 7 | +{description} |
| 8 | + |
| 9 | +== About Pre-filtering |
| 10 | + |
| 11 | +Using pre-filtering as part of your vector search offers two key advantages: |
| 12 | + |
| 13 | +. *Enhanced precision and relevance:* |
| 14 | +Narrow your search results based on specific criteria, such as organization, date/time ranges, or geospatial locations. |
| 15 | + |
| 16 | +. *Performance optimization:* |
| 17 | +Reduce the search space before executing queries to improve query execution time and reduce computational overhead. |
| 18 | + |
| 19 | +== Prerequisites |
| 20 | + |
| 21 | +* You have the Search Service enabled on a node in your database. |
| 22 | +For more information about how to deploy a new node and Services on your database, see xref:server:manage:manage-nodes/node-management-overview.adoc[]. |
| 23 | + |
| 24 | +* You have a bucket with scopes and collections in your database. |
| 25 | +For more information about how to create a bucket, see xref:server:manage:manage-buckets/create-bucket.adoc[]. |
| 26 | + |
| 27 | +* Your user account has the *Search Admin* or *Search Reader* role. |
| 28 | + |
| 29 | +* You installed the Couchbase command-line tool (CLI). |
| 30 | + |
| 31 | +* You have the hostname or IP address for the node in your database where you're running the Search Service. |
| 32 | +For more information about where to find the IP address for your node, see xref:server:manage:manage-nodes/list-cluster-nodes.adoc[]. |
| 33 | + |
| 34 | +* You have created a Vector Search index. |
| 35 | ++ |
| 36 | +For more information about how to create a Vector Search index, see xref:create-vector-search-index-ui.adoc[] or xref:create-vector-search-index-rest-api.adoc[]. |
| 37 | ++ |
| 38 | +[TIP] |
| 39 | +-- |
| 40 | +include::partial$download-sample-partial.adoc[] |
| 41 | + |
| 42 | +For the best results, consider using the sample Vector Search index from xref:create-vector-search-index-ui.adoc#example[Create a Vector Search Index with the {page-ui-name}] or xref:create-vector-search-index-rest-api.adoc#example[Create a Vector Search Index with the REST API and curl/HTTP]. |
| 43 | +-- |
| 44 | + |
| 45 | +== Procedure |
| 46 | + |
| 47 | +To run a pre-filtered vector search with the REST API: |
| 48 | + |
| 49 | +. In your command-line tool, enter a `curl` command with the `XPOST` verb. |
| 50 | +. Set your header content to include `"Content-Type: application/json"`. |
| 51 | +. Add your `username`, `password`, and the Search Service endpoint on port `8094`. |
| 52 | +. Add the `index name` you want to query to the endpoint. |
| 53 | + |
| 54 | +[source, console] |
| 55 | +---- |
| 56 | +curl -XPOST -H "Content-Type: application/json" \ |
| 57 | + -u ${CB_USERNAME}:${CB_PASSWORD} http://${CB_HOSTNAME}:8094/api/bucket/vector-sample/scope/color/index/{INDEX_NAME}/query \ |
| 58 | +-d \ |
| 59 | +---- |
| 60 | + |
| 61 | +=== Example |
| 62 | + |
| 63 | +In the following example, you will extend a search query |
| 64 | +to find matches in `color-index`. |
| 65 | + A pre-filter on the query will narrow the documents in the index searched to those with a `color` field value |
| 66 | + that closely matches `navy`. |
| 67 | + |
| 68 | +[source, console] |
| 69 | +---- |
| 70 | +include::example$run-pre-filtered-vector-search-rest-api.sh[] |
| 71 | +---- |
| 72 | + |
| 73 | + |
0 commit comments