|
1 | 1 | = Vector Search |
2 | | -:page-toclevels: 2 |
| 2 | +:page-toclevels: 3 |
3 | 3 | :description: Vector Search from the SDK, to enable AI integration, semantic search, and use of RAG frameworks. |
4 | 4 |
|
5 | 5 |
|
@@ -125,39 +125,40 @@ If it was a global index we would use `cluster.search()` instead - see <<Scoped |
125 | 125 | It returns the same `SearchResult` detailed earlier. |
126 | 126 |
|
127 | 127 |
|
128 | | -===== Pre-Filters |
129 | | - |
130 | | -From Couchbase Server 7.6.4 -- and in Capella Operational clusters -- you can apply xref:server:vector-search:pre-filtering-vector-search.adoc#about-pre-filtering[pre-filtering with similarity search]. |
131 | | -The current version of the {name-sdk} supports this. |
132 | | - |
133 | | -This is applied to the search query sub-object within the knn array items for that vector query: |
134 | | - |
135 | | -[source,json] |
136 | | ----- |
137 | | -{ |
138 | | - "fields": ["artist", "song"], |
139 | | - "knn": [{ |
140 | | - "filter": { |
141 | | - "conjuncts": [{ |
142 | | - "match": "English", |
143 | | - "filed": "language" |
144 | | - }, { |
145 | | - "min": 1990, |
146 | | - "max": 2000, |
147 | | - "inclusive_min": false, |
148 | | - "inclusive_max": true, |
149 | | - "field": "year" |
150 | | - }] |
151 | | - }, |
152 | | - "k": 5, |
153 | | - "field": "music_vector", |
154 | | - "vector": [0.024901132253900747, 1535 vectors removed] |
155 | | - }], |
156 | | - "explain": true, |
157 | | - "size": 5, |
158 | | - "from": 0 |
159 | | -} |
| 128 | +==== Pre-Filters |
| 129 | + |
| 130 | +From Couchbase Server 7.6.4 -- and in Capella Operational clusters -- |
| 131 | +xref:server:vector-search:pre-filtering-vector-search.adoc#about-pre-filtering[pre-filtering with similarity search] is available. |
| 132 | +This is a non-vector query that the server executes first to get an intermediate result. |
| 133 | +Then it executes the vector query on the intermediate result to get the final result. |
| 134 | + |
| 135 | +[source,java] |
| 136 | +---- |
| 137 | +`public VectorQuery prefilter(SearchQuery prefilter)` |
| 138 | +---- |
| 139 | + |
| 140 | +If no prefilter is specified, the server executes the vector query on all indexed documents. |
| 141 | + |
| 142 | +[source,java] |
160 | 143 | ---- |
| 144 | + .setOptions(VectorQueryOptions.newBuilder() |
| 145 | + .setNumCandidates(numCandidates) |
| 146 | + .setPrefilter(SearchQuery.newBuilder() |
| 147 | + .setMatch(MatchQuery.newBuilder() |
| 148 | + .setMatch("primary").setField("color_wheel_pos")))) |
| 149 | +---- |
| 150 | + |
| 151 | +The prefilter can be any Search Query -- |
| 152 | +from a simple match, as above, to a string query: |
| 153 | + |
| 154 | +[source,java] |
| 155 | +---- |
| 156 | + .setPrefilter(SearchQuery.newBuilder() |
| 157 | + .setQueryString(QueryStringQuery.newBuilder() |
| 158 | + .setQuery("+description:sea -color_hex:fff5ee"))) |
| 159 | +---- |
| 160 | + |
| 161 | +See the link:++https://docs.couchbase.com/sdk-api/couchbase-java-client/com/couchbase/client/java/search/vector/VectorQuery.html#prefilter(com.couchbase.client.java.search.SearchQuery)++[API reference]. |
161 | 162 |
|
162 | 163 |
|
163 | 164 | ==== Multiple vector queries |
|
0 commit comments