kernel-memory: [Bug] Postgres causes ArgumentOutOfRangeException in PostgresDbClient.ConnectAsync
Context / Scenario
We’re running Kernel Memory as a docker image on Google Cloud Run, and using Google Postgres SQL as vector index. Queue & Storage is on Azure Blob Storage.
When ingesting documents, it throws an ArgumentOutOfRangeException when trying to connect to Postgres.
What happened?
When ingesting documents, it throws an ArgumentOutOfRangeException when trying to connect to Postgres.
Instead, I expect it to ingest successfully.
It has worked initially when I tested to ingest about 10 documents. But now it no longer works, despite restarting it. I’m trying to ingest the same documents, so it is trying to delete the record now first, which then fails with below error.
Importance
I cannot use Kernel Memory
Platform, Language, Versions
Using latest Docker version on Google Cloud Run using Google Postgres SQL, using the latest docker image. Connection string is configured like so:
value: Host=/cloudsql/PROJECT_ID:REGIO:km-postgres;Port=5432;Username=USER;Password=PASS;Database=km-default
On Postgres, I’ve run below to enable vector indexing & configured an index:
CREATE EXTENSION vector;
CREATE INDEX ON "km-default" USING hnsw (embedding vector_cosine_ops);
Queue & storage are on Azure Storage.
Relevant log output
[01:29:02.748] trce: Microsoft.KernelMemory.Postgres.PostgresDbClient[0] Deleting record 'd=28906//p=6d15ea9691ba4b5b8598a6504e29a011' from table 'public."km-default"'
System.ArgumentOutOfRangeException: Exception of type 'System.ArgumentOutOfRangeException' was thrown. (Parameter 'factory') Actual value was (, ).
at Npgsql.Internal.PgTypeInfoResolverChainBuilder.Build(Action`1 configure)
at Npgsql.NpgsqlSlimDataSourceBuilder.PrepareConfiguration()
at Npgsql.NpgsqlSlimDataSourceBuilder.Build() at Microsoft.KernelMemory.Postgres.PostgresDbClient.ConnectAsync(CancellationToken cancellationToken) in /src/extensions/Postgres/Postgres/Internals/PostgresDbClient.cs:line 670
at Microsoft.KernelMemory.Postgres.PostgresDbClient.DeleteAsync(String tableName, String id, CancellationToken cancellationToken) in /src/extensions/Postgres/Postgres/Internals/PostgresDbClient.cs:line 631
at Microsoft.KernelMemory.Handlers.SaveRecordsHandler.DeletePreviousRecordsAsync(DataPipeline pipeline, CancellationToken cancellationToken) in /src/service/Core/Handlers/SaveRecordsHandler.cs:line 319
at Microsoft.KernelMemory.Handlers.SaveRecordsHandler.InvokeAsync(DataPipeline pipeline, CancellationToken cancellationToken) in /src/service/Core/Handlers/SaveRecordsHandler.cs:line 111
at Microsoft.KernelMemory.Pipeline.DistributedPipelineOrchestrator.RunPipelineStepAsync(DataPipeline pipeline, IPipelineStepHandler handler, CancellationToken cancellationToken) in /src/service/Core/Pipeline/DistributedPipelineOrchestrator.cs:line 226
at Microsoft.KernelMemory.Pipeline.DistributedPipelineOrchestrator.<>c__DisplayClass5_0.<<AddHandlerAsync>b__0>d.MoveNext() in /src/service/Core/Pipeline/DistributedPipelineOrchestrator.cs:line 167 --- End of stack trace from previous location ---
at Microsoft.KernelMemory.Orchestration.AzureQueues.AzureQueuesPipeline.<>c__DisplayClass20_0.<<OnDequeue>b__0>d.MoveNext() in /src/extensions/AzureQueues/AzureQueuesPipeline.cs:line 197
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 23 (18 by maintainers)
Commits related to this issue
- Change Postgres connection handling (#811) ## Motivation and Context (Why the change? What's the scenario?) ArgumentOutOfRangeException when trying to connect to Postgres. See https://github.com/mi... — committed to microsoft/kernel-memory by marcominerva 2 years ago
- Revert Postgres connection handling (#823) ## Motivation and Context (Why the change? What's the scenario?) Fix exceptions in Postgres connector. See https://github.com/microsoft/kernel-memory/is... — committed to microsoft/kernel-memory by marcominerva 2 years ago
- Change Postgres connection handling (#811) ## Motivation and Context (Why the change? What's the scenario?) ArgumentOutOfRangeException when trying to connect to Postgres. See https://github.com/mi... — committed to sangar-1028/kernel-memory by sangar-1028 2 years ago
- Revert Postgres connection handling (#823) ## Motivation and Context (Why the change? What's the scenario?) Fix exceptions in Postgres connector. See https://github.com/microsoft/kernel-memory/is... — committed to sangar-1028/kernel-memory by sangar-1028 2 years ago
Thanks @dluc and @marcominerva for all the support and input. I’ve deployed the latest version to our prod instance and after ~24 hours still going well.
thanks @marcominerva PR merged into 0.77 and docker images updated
@dluc I have sent the PR I was talking about, take a look at it: https://github.com/microsoft/kernel-memory/pull/823.
About the docker images, we had to wipe the docker registry because it was too expensive maintaining all versions, plus the new dockerization pipeline won’t produce versions anymore. From now on docker hub will provide only 2 labels, “latest” for AMD64 arch and “latest-arm64” for ARM64 arch. I’ve tried fixing the pipeline for several days, because it was broken for ARM64, and all those images were broken too, but I’ve been unable to find a good solution.
In case people need specific builds tight to a specific commit/version we recommend managing the dockerization process in house, in their CI/CD platform, using the Dockerfile provided in the repo.
@dluc It seems that in particular cases there could be some issues if the Data Source is disposed before the actual work with the Connection (like in the current implementation, where it is disposed right after opening the connection):
I have changed the
PostgresDbClientimplementation to ensure that the Data Source is disposed only at the end of the work: https://github.com/microsoft/kernel-memory/pull/811.