Skip to content

Commit 06a0e0e

Browse files
committed
[DOC-12609]: Document the extension to vector syntax to support pre filtering: MB-62230 (#285)
* [DOC-12609]: Document the extension to vector syntax to support pre filtering: MB-62230 * [DOC-12609]: Document the extension to vector syntax to support pre filtering: MB-62230 Fleshing out the text following review. Tidied up the advantages list. * [DOC-12609]: Document the extension to vector syntax to support pre-filtering: MB-62230 Fixups following review.
1 parent 0ef4746 commit 06a0e0e

File tree

3 files changed

+97
-0
lines changed

3 files changed

+97
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
curl -XPOST -H "Content-Type: application/json" \
2+
-u ${CB_USERNAME}:${CB_PASSWORD} http://${CB_HOSTNAME}:8094/api/bucket/vector-sample/scope/color/index/color-index/query \
3+
-d '{
4+
"fields": ["*"],
5+
"query": {
6+
"min": 70,
7+
"max": 80,
8+
"inclusive_min": false,
9+
"inclusive_max": true,
10+
"field": "brightness"
11+
},
12+
"knn": [
13+
{
14+
"k": 10,
15+
"field": "colorvect_l2",
16+
"vector": [ 176, 0, 176 ],
17+
"filter": {
18+
"field: "color",
19+
"match": "navy"
20+
}
21+
}
22+
]
23+
}'
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
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+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
* xref:cloud:vector-search:vector-search.adoc[]
22
** xref:cloud:vector-search:create-vector-search-index-ui.adoc[]
3+
** xref:cloud:vector-search:pre-filtering-vector-search.adoc[]
34
** xref:cloud:vector-search:run-vector-search-ui.adoc[]
45
** xref:cloud:vector-search:run-vector-search-sdk.adoc[]
56
** xref:cloud:vector-search:fine-tune-vector-search.adoc[]

0 commit comments

Comments
 (0)