From a7e68ec6e197610b374d97eb84249161e58ae8c4 Mon Sep 17 00:00:00 2001 From: Konstantine Kalbazov Date: Fri, 12 Jul 2024 20:53:16 +0200 Subject: [PATCH 1/2] fix: maxDistance cast to string during string interpolation if dotnet culture is set to French it used comma as the decimal separator instead of period, which cased SQL error "unexpected ," --- extensions/Postgres/Postgres/Internals/PostgresDbClient.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/extensions/Postgres/Postgres/Internals/PostgresDbClient.cs b/extensions/Postgres/Postgres/Internals/PostgresDbClient.cs index bd9b1854d..7327a93fd 100644 --- a/extensions/Postgres/Postgres/Internals/PostgresDbClient.cs +++ b/extensions/Postgres/Postgres/Internals/PostgresDbClient.cs @@ -1,6 +1,7 @@ // Copyright (c) Microsoft. All rights reserved. using System; +using System.Globalization; using System.Collections.Generic; using System.Runtime.CompilerServices; using System.Security.Cryptography; @@ -415,7 +416,7 @@ DO UPDATE SET } var maxDistance = 1 - minSimilarity; - filterSql += $" AND {this._colEmbedding} <=> @embedding < {maxDistance}"; + filterSql += $" AND {this._colEmbedding} <=> @embedding < {maxDistance.ToString(CultureInfo.InvariantCulture)}"; if (sqlUserValues == null) { sqlUserValues = new(); } From 68e0a9f21f15c199f3f39d4a70994dfb2286b856 Mon Sep 17 00:00:00 2001 From: Konstantine Kalbazov Date: Tue, 16 Jul 2024 09:24:56 +0200 Subject: [PATCH 2/2] refactor: use maxDistance as param instead of casting to string --- extensions/Postgres/Postgres/Internals/PostgresDbClient.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/extensions/Postgres/Postgres/Internals/PostgresDbClient.cs b/extensions/Postgres/Postgres/Internals/PostgresDbClient.cs index 7327a93fd..fd7fdcddf 100644 --- a/extensions/Postgres/Postgres/Internals/PostgresDbClient.cs +++ b/extensions/Postgres/Postgres/Internals/PostgresDbClient.cs @@ -1,7 +1,6 @@ // Copyright (c) Microsoft. All rights reserved. using System; -using System.Globalization; using System.Collections.Generic; using System.Runtime.CompilerServices; using System.Security.Cryptography; @@ -416,7 +415,7 @@ DO UPDATE SET } var maxDistance = 1 - minSimilarity; - filterSql += $" AND {this._colEmbedding} <=> @embedding < {maxDistance.ToString(CultureInfo.InvariantCulture)}"; + filterSql += $" AND {this._colEmbedding} <=> @embedding < @maxDistance"; if (sqlUserValues == null) { sqlUserValues = new(); } @@ -448,6 +447,7 @@ OFFSET @offset "; cmd.Parameters.AddWithValue("@embedding", target); + cmd.Parameters.AddWithValue("@maxDistance", maxDistance); cmd.Parameters.AddWithValue("@limit", limit); cmd.Parameters.AddWithValue("@offset", offset);