Skip to content

Commit

Permalink
Fix #96 - Add order by cosine_similarity desc to getSimilarList reque…
Browse files Browse the repository at this point in the history
…sts (#99)
  • Loading branch information
kbeaugrand authored Jan 22, 2024
1 parent e0faef8 commit c448290
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/Connectors.Memory.SqlServer/SqlServerClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,8 @@ FOR JSON AUTO
[similarity]
INNER JOIN
{this.GetFullTableName(this._configuration.MemoryTableName)} ON [similarity].[memory_id] = {this.GetFullTableName(this._configuration.MemoryTableName)}.[id]
WHERE cosine_similarity >= @min_relevance_score";
WHERE [cosine_similarity] >= @min_relevance_score
ORDER BY [cosine_similarity] desc";

cmd.Parameters.AddWithValue("@vector", embedding);
cmd.Parameters.AddWithValue("@collection", collectionName);
Expand Down
5 changes: 3 additions & 2 deletions src/KernelMemory.MemoryStorage.SqlServer/SqlServerMemory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -321,8 +321,9 @@ SELECT DISTINCT
INNER JOIN
{this.GetFullTableName(this._config.MemoryTableName)} ON [similarity].[memory_id] = {this.GetFullTableName(this._config.MemoryTableName)}.[id]
WHERE 1=1
AND cosine_similarity >= @min_relevance_score
{GenerateFilters(index, cmd.Parameters, filters)}";
AND [cosine_similarity] >= @min_relevance_score
{GenerateFilters(index, cmd.Parameters, filters)}
ORDER BY [cosine_similarity] desc";

cmd.Parameters.AddWithValue("@vector", JsonSerializer.Serialize(embedding.Data.ToArray()));
cmd.Parameters.AddWithValue("@index", index);
Expand Down

0 comments on commit c448290

Please sign in to comment.