-
Notifications
You must be signed in to change notification settings - Fork 3.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
.Net: Add PostgresVectorStore Memory connector. #9324
Open
lossyrob
wants to merge
73
commits into
microsoft:main
Choose a base branch
from
lossyrob:feature/postgres-vector-store-dotnet
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 35 commits
Commits
Show all changes
73 commits
Select commit
Hold shift + click to select a range
8778d5f
Add PostgresVectorStore Memory connector.
ddad99a
Add UpsertBatch, GetBatch, and DeleteBatch
5447815
Remove unused CreateMapping
7533f8c
Merge remote-tracking branch 'upstream/main' into feature/postgres-ve…
9a4f836
Merge remote-tracking branch 'upstream/main' into feature/postgres-ve…
68a000e
Add vector search to PostgresVectorStore
317f6af
create index on collection creation
f4f5ba2
Support Guid, test distance functions
2acf118
Format tests
5db2c59
Merge remote-tracking branch 'upstream/main' into feature/postgres-ve…
f4b4dc5
Add service and kernel extensions
5c58400
Default to Euclidean distance if no distance function is specified
8ea21cd
Add Postgres sample to concepts
4dcd222
Add docs for setting configuration in samples\Concepts
74b3764
Merge remote-tracking branch 'upstream/main' into feature/postgres-ve…
5c3e63f
Enforce dimension size in index creation
6d9f1fd
Create index for CreateTableIfNotExistsAsyc
b4266cc
Log warning when index not created due to dimensions
f86613a
Refactor and tests; make SqlBuilder internal
716b794
Merge remote-tracking branch 'upstream/main' into feature/postgres-ve…
8d8283b
Remove old migration note
89027fc
Fix docstring
8f45d9c
Use parameter for tableName
48811bd
Fix support for DateTime, DateTimeOffset
1d6082d
Fix warnings in test
eb0a683
Remove kernel extensions, improve service extensions
a66d835
Make PostgresSqlCommandInfo internal
53f1009
Default to a Hnsw index
08ea55f
Default to cosine distance
319648b
Consistently use includeVectors
5b52bdc
Simplify AsyncEnumerable return
cd845ee
Pass properties instead of full definition
1d09a21
Throw instead of log for too high dimensionality
74e9757
Remove DefaultVectorSize
ad5628c
Remove unused using statements
dbf1aef
Remove VectorStore constructor that creates datsaource
a355bf7
Fix duplicate mapper call
e499a80
Fix docstring typo
c95e2b3
Comment clarifying that multiple keys should be previously validated
9d972b3
Refactor ExecuteNonQueryAsync calls to reduce code dupe
6eb3793
Forward Schema option.
ed59fed
Make PostgresVectorStoreDbClient internal
1749adb
Support more enumerable types
ea7b01c
Merge remote-tracking branch 'upstream/main' into feature/postgres-ve…
86486d7
Refactor to support default + transactions
b9b4a44
Fix issue with converting readonly array on upsert
c53a8ee
Merge remote-tracking branch 'upstream/main' into feature/postgres-ve…
97ef60a
Fix SLN merge error
81e1805
Improve error handling
a587260
Avoid CA1859 in test class
e8fe800
Account for ngpsql missing func in .net std 2.0
96c088e
Fix servicecollection tests
0fc76f6
Logic for dimension max moved and tested elsewhere
266310b
Remove unused using statement
08f110c
Remove logger from PostgresVectorStoreRecordCollection
26516c5
Merge branch 'main' into feature/postgres-vector-store-dotnet
lossyrob 5b44a80
Use Flat instead of None index kind
b9b2487
Merge remote-tracking branch 'upstream/main' into feature/postgres-ve…
24577a0
Remove unnecessary overloads
60d6512
Change tests to be true to name
5a66a13
Remove reduntant key type based test
581b6ab
Remove unnecessary overloads
494a0d4
Better error handling for IAsyncEnumerable
5f19889
Default to Flat (no index) instead of Hnsw
62ac8eb
Add enumerable to record mapper test
364b592
Remove unused fixture properties
bf58cab
Test StoragePropertyName in sql builder tests
aa592de
Remove dynamic from integration test
9a3b216
Add test to read from manually inserted record
1ee09c1
Merge remote-tracking branch 'upstream/main' into feature/postgres-ve…
b037075
Formatting, spelling
29d91ba
Merge remote-tracking branch 'upstream/main' into feature/postgres-ve…
c2937e0
Fix test.
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
|
||
using System; | ||
using System.Collections.Generic; | ||
using Microsoft.Extensions.VectorData; | ||
|
||
namespace Microsoft.SemanticKernel.Connectors.Postgres; | ||
|
||
|
@@ -35,20 +36,29 @@ internal static class PostgresConstants | |
typeof(decimal), | ||
typeof(decimal?), | ||
typeof(string), | ||
typeof(DateTime), | ||
typeof(DateTime?), | ||
typeof(DateTimeOffset), | ||
typeof(DateTimeOffset?), | ||
typeof(Guid), | ||
typeof(Guid?), | ||
typeof(byte[]), | ||
typeof(List<bool>), | ||
typeof(List<short>), | ||
typeof(List<int>), | ||
typeof(List<long>), | ||
typeof(List<float>), | ||
typeof(List<double>), | ||
typeof(List<decimal>), | ||
typeof(List<string>), | ||
typeof(List<DateTimeOffset>), | ||
]; | ||
|
||
/// <summary>A <see cref="HashSet{T}"/> of types that enumerable data properties on the provided model may use as their element types.</summary> | ||
public static readonly HashSet<Type> SupportedEnumerableDataElementTypes = | ||
[ | ||
typeof(bool), | ||
typeof(short), | ||
typeof(int), | ||
typeof(long), | ||
typeof(float), | ||
typeof(double), | ||
typeof(decimal), | ||
typeof(string), | ||
typeof(DateTime), | ||
typeof(DateTimeOffset), | ||
typeof(Guid), | ||
]; | ||
|
||
/// <summary>A <see cref="HashSet{T}"/> of types that vector properties on the provided model may have.</summary> | ||
|
@@ -64,4 +74,15 @@ internal static class PostgresConstants | |
/// <summary>The name of the column that returns distance value in the database.</summary> | ||
/// <remarks>It is used in the similarity search query. Must not conflict with model property.</remarks> | ||
public const string DistanceColumnName = "sk_pg_distance"; | ||
|
||
/// <summary>The default index kind.</summary> | ||
public const string DefaultIndexKind = IndexKind.Hnsw; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's also OK to use Flat here as the default. When I was suggesting using Hnsw earlier, I didn't realise that postgres can also work without, and that's a totally acceptable default. |
||
|
||
/// <summary>The default distance function.</summary> | ||
public const string DefaultDistanceFunction = DistanceFunction.CosineDistance; | ||
|
||
public static readonly Dictionary<string, int> IndexMaxDimensions = new() | ||
{ | ||
{ IndexKind.Hnsw, 2000 }, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 0 additions & 84 deletions
84
dotnet/src/Connectors/Connectors.Memory.Postgres/PostgresKernelBuilderExtensions.cs
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PostgresVectorStoreRecordPropertyMapping
does not have aDateTimeOffset
mapping, but does have aDateTime
mapping.