You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -141,18 +143,26 @@ foreach (var (blog, score) in blogs)
141
143
This translates to the following SQL:
142
144
143
145
```sql
144
-
SELECT [v].[Id], [v].[Name], [v].[Distance]
145
-
FROM VECTOR_SEARCH([Blogs], 'Embedding', @__embedding, 'metric = cosine', @__topN)
146
+
SELECT TOP(@p) WITH APPROXIMATE [b].[Id], [b].[Name], [v].[Distance]
147
+
FROM VECTOR_SEARCH(
148
+
TABLE = [Blogs] AS [b],
149
+
COLUMN = [Embedding],
150
+
SIMILAR_TO = @p1,
151
+
METRIC ='cosine'
152
+
) AS [v]
153
+
ORDER BY [v].[Distance]
146
154
```
147
155
148
-
The `topN` parameter specifies the maximum number of results to return.
156
+
Compose `VectorSearch()` with `OrderBy(r => r.Distance)` and `Take(...)` to limit the number of results returned as required for approximate vector search.
149
157
150
158
`VectorSearch()` returns `VectorSearchResult<TEntity>`, which allows you to access both the entity and the computed distance:
This translates to the SQL Server [`VECTOR_SEARCH()`](/sql/t-sql/functions/vector-search-transact-sql) table-valued function, which performs an approximate search over the vector index. The `topN` parameter specifies the number of results to return.
239
+
This translates to the SQL Server [`VECTOR_SEARCH()`](/sql/t-sql/functions/vector-search-transact-sql) table-valued function, which performs an approximate search over the vector index. Compose with `OrderBy(r => r.Distance)` and `Take(...)` to limit the number of results returned.
238
240
239
241
`VectorSearch()` returns `VectorSearchResult<TEntity>`, allowing you to access the distance alongside the entity.
0 commit comments