Skip to content

Commit ec2802c

Browse files
Merge pull request #252505 from HeidiSteen/heidist-freshness
[azure search] GH vector filter correction
2 parents 58b1605 + ee902fd commit ec2802c

File tree

2 files changed

+43
-8
lines changed

2 files changed

+43
-8
lines changed

articles/search/vector-search-how-to-query.md

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ In Azure Cognitive Search, if you added vector fields to a search index, this ar
1919

2020
> [!div class="checklist"]
2121
> + [Query vector fields](#query-syntax-for-vector-search).
22+
> + [Filter and query vector fields](#filter-and-vector-queries)
2223
> + [Combine vector, full text search, and semantic search in a hybrid query](#query-syntax-for-hybrid-search).
2324
> + [Query multiple vector fields at once](#query-syntax-for-vector-query-over-multiple-fields).
2425
> + [Run multiple vector queries in parallel](#query-syntax-for-multiple-vector-queries).
@@ -127,7 +128,7 @@ In this vector query, which is shortened for brevity, the "value" contains the v
127128
In the following example, the vector is a representation of this query string: `"what Azure services support full text search"`. The query request targets the "contentVector" field. The actual vector has 1536 embeddings. It's trimmed in this example for readability.
128129

129130
```http
130-
POST https://{{search-service-name}}.search.windows.net/indexes/{{index-name}}/docs/search?api-version={{api-version}}
131+
POST https://{{search-service-name}}.search.windows.net/indexes/{{index-name}}/docs/search?api-version=2023-07-01-Preview
131132
Content-Type: application/json
132133
api-key: {{admin-api-key}}
133134
{
@@ -221,16 +222,50 @@ Here's a modified example so that you can see the basic structure of a response
221222

222223
---
223224

225+
## Filter and vector queries
226+
227+
A query request can include a vector query and a [filter expression](search-filters.md). Filters apply to text and numeric fields, and are useful for including or excluding search documents based on filter criteria. Although a vector field isn't filterable itself, you can attribute a text or numeric field in the same index as "filterable".
228+
229+
In contrast with full text search, a filter in a pure vector query is effectively processed as a post-query operation. The set of `"k"` nearest neighbors is retrieved, and then combined with the set of filtered results. As such, the value of `"k"` predetermines the surface over which the filter is applied. For `"k": 10`, the filter is applied to 10 most similar documents. For `"k": 100`, the filter iterates over 100 documents (assuming the index contains 100 documents that are sufficiently similar to the query).
230+
231+
Here's an example of filter expressions combined with a vector query:
232+
233+
```http
234+
POST https://{{search-service-name}}.search.windows.net/indexes/{{index-name}}/docs/search?api-version=2023-07-01-Preview
235+
Content-Type: application/json
236+
api-key: {{admin-api-key}}
237+
{
238+
"vectors": [
239+
{
240+
"value": [
241+
-0.009154141,
242+
0.018708462,
243+
. . .
244+
-0.02178128,
245+
-0.00086512347
246+
],
247+
"fields": "contentVector",
248+
"k": 10
249+
},
250+
],
251+
"select": "title, content, category",
252+
"filter": "category eq 'Databases'"
253+
}
254+
```
255+
256+
> [!TIP]
257+
> If you don't have source fields with text or numeric values, check for document metadata, such as LastModified or CreatedBy properties, that might be useful in a filter.
258+
224259
## Query syntax for hybrid search
225260

226261
A hybrid query combines full text search and vector search, where the `"search"` parameter takes a query string and `"vectors.value"` takes the vector query. The search engine runs full text and vector queries in parallel. All matches are evaluated for relevance using Reciprocal Rank Fusion (RRF) and a single result set is returned in the response.
227262

228-
Hybrid queries are useful because they add support for filters, orderby, and [semantic search](semantic-how-to-query-request.md) For example, in addition to the vector query, you could filter by location or search over product names or titles, scenarios for which similarity search isn't a good fit.
263+
Hybrid queries are useful because they add support for filters, orderby, and [semantic search](semantic-how-to-query-request.md) For example, in addition to the vector query, you could search over people or product names or titles, scenarios for which similarity search isn't a good fit.
229264

230265
The following example is from the [Postman collection of REST APIs](https://github.com/Azure/cognitive-search-vector-pr/tree/main/demo-python) that demonstrate query configurations. It shows a complete request that includes vector search, full text search with filters, and semantic search with captions and answers. Semantic search is an optional premium feature. It's not required for vector search or hybrid search. For content that includes rich descriptive text *and* vectors, it's possible to benefit from all of the search modalities in one request.
231266

232267
```http
233-
POST https://{{search-service-name}}.search.windows.net/indexes/{{index-name}}/docs/search?api-version={{api-version}}
268+
POST https://{{search-service-name}}.search.windows.net/indexes/{{index-name}}/docs/search?api-version=2023-07-01-Preview
234269
Content-Type: application/json
235270
api-key: {{admin-api-key}}
236271
{
@@ -262,7 +297,7 @@ api-key: {{admin-api-key}}
262297
You can set the "vectors.fields" property to multiple vector fields. For example, the Postman collection has vector fields named "titleVector" and "contentVector". A single vector query executes over both the "titleVector" and "contentVector" fields, which must have the same embedding space since they share the same query vector.
263298

264299
```http
265-
POST https://{{search-service-name}}.search.windows.net/indexes/{{index-name}}/docs/search?api-version={{api-version}}
300+
POST https://{{search-service-name}}.search.windows.net/indexes/{{index-name}}/docs/search?api-version=2023-07-01-Preview
266301
Content-Type: application/json
267302
api-key: {{admin-api-key}}
268303
{

articles/search/vector-search-overview.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ author: robertklee
77
ms.author: robertlee
88
ms.service: cognitive-search
99
ms.topic: conceptual
10-
ms.date: 08/10/2023
10+
ms.date: 09/21/2023
1111
---
1212

1313
# Vector search within Azure Cognitive Search
@@ -41,7 +41,7 @@ On the indexing side, prepare source documents that contain embeddings. Cognitiv
4141

4242
On the query side, in your client application, collect the query input. Add a step that converts the input into a vector, and then send the vector query to your index on Cognitive Search for a similarity search. Cognitive Search returns documents with the requested `k` nearest neighbors (kNN) in the results.
4343

44-
You can index vector data as fields in documents alongside alphanumeric content. Vector queries can be issued singly or in combination with other query types, including term queries (hybrid search) and filters and semantic re-ranking in the same search request.
44+
You can index vector data as fields in documents alongside alphanumeric content. Vector queries can be issued singly or in combination with filters and other query types, including term queries (hybrid search) and semantic ranking in the same search request.
4545

4646
## Limitations
4747

@@ -66,9 +66,9 @@ Scenarios for vector search include:
6666

6767
+ **Multi-lingual search**. Use a multi-lingual embeddings model to represent your document in multiple languages in a single vector space to find documents regardless of the language they are in.
6868

69-
+ **Hybrid search**. Vector search is implemented at the field level, which means you can build queries that include vector fields and searchable text fields. The queries execute in parallel and the results are merged into a single response. Optionally, add [semantic search (preview)](semantic-search-overview.md) for even more accuracy with L2 reranking using the same language models that power Bing.
69+
+ **Hybrid search**. Vector search is implemented at the field level, which means you can build queries that include both vector fields and searchable text fields. The queries execute in parallel and the results are merged into a single response. Optionally, add [semantic search (preview)](semantic-search-overview.md) for even more accuracy with L2 reranking using the same language models that power Bing.
7070

71-
+ **Filtered vector search**. A query request can include a vector query and a [filter expression](search-filters.md). Filters apply to text and numeric fields, and are useful for including or excluding search documents based on filter criteria. Although a vector field isn't filterable itself, you can set up a filterable text or numeric field. The search engine processes the filter first, reducing the surface area of the search corpus before running the vector query.
71+
+ **Filtered vector search**. A query request can include a vector query and a [filter expression](search-filters.md). Filters apply to text and numeric fields, and are useful for including or excluding search documents based on filter criteria. Although a vector field isn't filterable itself, you can set up a filterable text or numeric field. The search engine processes the filter after the vector query executes, trimming search results from query response.
7272

7373
+ **Vector database**. Use Cognitive Search as a vector store to serve as long-term memory or an external knowledge base for Large Language Models (LLMs), or other applications. For example, you can use Azure Cognitive Search as a [*vector index* in an Azure Machine Learning prompt flow](/azure/machine-learning/concept-vector-stores) for Retrieval Augmented Generation (RAG) applications.
7474

0 commit comments

Comments
 (0)