Skip to content

Commit

Permalink
Merge pull request #33 from dabedin/patch-1
Browse files Browse the repository at this point in the history
InvariantCulture to avoid syntax errors in CosmoDb query
  • Loading branch information
feaselkl authored Nov 14, 2024
2 parents d37c63f + d5ebaf4 commit 4181968
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions docs/03_implement_vector_search_in_cosmos_db_nosql/0303.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,11 @@ The key tasks are as follows:
3. Provide a method named `ExecuteVectorSearch` in the `VectorizationService` for executing a vector search query against Azure Cosmos DB. The method should accept vectorized query text (called `queryVector`), the maximum number of results to return (named `max_results`), and the minimum similarity score (named `minimum_similarity_score`) and execute a query using the `VectorDistance()` function. It should return a list of `VectorSearchResult` objects. The count should limit the number of results returned. The query executed in Cosmos DB should use the following pattern:
```csharp
var query = $"SELECT c.hotel_id AS HotelId, c.hotel AS Hotel, c.details AS Details, c.source AS Source, VectorDistance(c.request_vector, [{string.Join(",", queryVector)}]) AS SimilarityScore FROM c";
query += $" WHERE VectorDistance(c.request_vector, [{string.Join(",", queryVector)}]) > {minimum_similarity_score}";
query += $" ORDER BY VectorDistance(c.request_vector, [{string.Join(",", queryVector)}])";
var vectorString = string.Join(", ", queryVector.Select(v => v.ToString(CultureInfo.InvariantCulture)).ToArray());
var query = $"SELECT c.hotel_id AS HotelId, c.hotel AS Hotel, c.details AS Details, c.source AS Source, VectorDistance(c.request_vector, [{vectorString}]) AS SimilarityScore FROM c";
query += $" WHERE VectorDistance(c.request_vector, [{vectorString}]) > {minimum_similarity_score.ToString(CultureInfo.InvariantCulture)}";
query += $" ORDER BY VectorDistance(c.request_vector, [{vectorString}])";
```
<details markdown="block">
Expand Down

0 comments on commit 4181968

Please sign in to comment.