Skip to content

Bug: The CopilotChatWebApi backend should invoke CreateCollectionAsync once at least for each chat session when use PostgresMemoryStore with local postgresql database as vectors MemoryStore #215

@AwesomeYuer

Description

@AwesomeYuer

Describe the bug

The WebAPI backend should invoke CreateCollectionAsync once at least for each chat session when use PostgresMemoryStore and local postgresql database as vectors MemoryStore

To Reproduce
Steps to reproduce the behavior:

  1. running local postgres server
  2. modify CopilotChatWebApi appsettings.json
"MemoryStore": {
  "Type": "postgres",
  "Qdrant": {
    "Host": "http://localhost",
    "Port": "6333",
    "VectorSize": 1536
    // "Key":  ""
  },
  "AzureCognitiveSearch": {
    "Endpoint": ""
    // "Key": ""
  },
  "Chroma": {
    "Host": "http://localhost",
    "Port": "8000"
  },
  "Postgres": {
    "VectorSize": 1536
    // "ConnectionString": // dotnet user-secrets set "MemoryStore:Postgres:ConnectionString" "MY_POSTGRES_CONNECTION_STRING"
  }
},
  1. modify CopilotChatWebApi user secrets.json
{
  "AIService:Key": "eeXXXXXXXXXXXXXXXXXXXXXXX",
  "MemoryStore:Postgres:ConnectionString": "Host=localhost;Database=postgres;User Id=postgres;Password=password01!"
}
  1. Debug CopilotChatWebApi in VS2022
  2. Run webapp in VSCode using command
yarn serve
  1. chat in new session in webapp UI
  2. see same error in webapp frontend and webapi backend console
fail: Microsoft.SemanticKernel.IKernel[0]
      Something went wrong while executing the native function. Function: <GetDelegateInfo>b__0. Error: 42P01: relation "public.d8ff415b-167b-4b1a-8dd8-7d62f97f120d-LongTermMemory" does not exist

      POSITION: 115
      Npgsql.PostgresException (0x80004005): 42P01: relation "public.d8ff415b-167b-4b1a-8dd8-7d62f97f120d-LongTermMemory" does not exist

      POSITION: 115
         at Npgsql.Internal.NpgsqlConnector.<ReadMessage>g__ReadMessageLong|221_0(NpgsqlConnector connector, Boolean async, DataRowLoadingMode dataRowLoadingMode, Boolean readingNotifications, Boolean isReadingPrependedMessage)
         at Npgsql.NpgsqlDataReader.NextResult(Boolean async, Boolean isConsuming, CancellationToken cancellationToken)
         at Npgsql.NpgsqlDataReader.NextResult(Boolean async, Boolean isConsuming, CancellationToken cancellationToken)
         at Npgsql.NpgsqlCommand.ExecuteReader(CommandBehavior behavior, Boolean async, CancellationToken cancellationToken)
         at Npgsql.NpgsqlCommand.ExecuteReader(CommandBehavior behavior, Boolean async, CancellationToken cancellationToken)
         at Microsoft.SemanticKernel.Connectors.Memory.Postgres.PostgresDbClient.GetNearestMatchesAsync(String tableName, Vector embedding, Int32 limit, Double minRelevanceScore, Boolean withEmbeddings, CancellationToken cancellationToken)+MoveNext() in D:\MyGitHub\semantic-kernel@microshaoft-Debug\dotnet\src\Connectors\Connectors.Memory.Postgres\PostgresDbClient.cs:line 166
         at Microsoft.SemanticKernel.Connectors.Memory.Postgres.PostgresDbClient.GetNearestMatchesAsync(String tableName, Vector embedding, Int32 limit, Double minRelevanceScore, Boolean withEmbeddings, CancellationToken cancellationToken)+MoveNext() in D:\MyGitHub\semantic-kernel@microshaoft-Debug\dotnet\src\Connectors\Connectors.Memory.Postgres\PostgresDbClient.cs:line 173
         at Microsoft.SemanticKernel.Connectors.Memory.Postgres.PostgresDbClient.GetNearestMatchesAsync(String tableName, Vector embedding, Int32 limit, Double minRelevanceScore, Boolean withEmbeddings, CancellationToken cancellationToken)+System.Threading.Tasks.Sources.IValueTaskSource<System.Boolean>.GetResult()
         at Microsoft.SemanticKernel.Connectors.Memory.Postgres.PostgresMemoryStore.GetNearestMatchesAsync(String collectionName, ReadOnlyMemory`1 embedding, Int32 limit, Double minRelevanceScore, Boolean withEmbeddings, CancellationToken cancellationToken)+MoveNext() in D:\MyGitHub\semantic-kernel@microshaoft-Debug\dotnet\src\Connectors\Connectors.Memory.Postgres\PostgresMemoryStore.cs:line 160
         at Microsoft.SemanticKernel.Connectors.Memory.Postgres.PostgresMemoryStore.GetNearestMatchesAsync(String collectionName, ReadOnlyMemory`1 embedding, Int32 limit, Double minRelevanceScore, Boolean withEmbeddings, CancellationToken cancellationToken)+MoveNext() in D:\MyGitHub\semantic-kernel@microshaoft-Debug\dotnet\src\Connectors\Connectors.Memory.Postgres\PostgresMemoryStore.cs:line 160
         at Microsoft.SemanticKernel.Connectors.Memory.Postgres.PostgresMemoryStore.GetNearestMatchesAsync(String collectionName, ReadOnlyMemory`1 embedding, Int32 limit, Double minRelevanceScore, Boolean withEmbeddings, CancellationToken cancellationToken)+System.Threading.Tasks.Sources.IValueTaskSource<System.Boolean>.GetResult()
         at Microsoft.SemanticKernel.Memory.SemanticTextMemory.SearchAsync(String collection, String query, Int32 limit, Double minRelevanceScore, Boolean withEmbeddings, CancellationToken cancellationToken)+MoveNext() in D:\MyGitHub\semantic-kernel@microshaoft-Debug\dotnet\src\SemanticKernel\Memory\SemanticTextMemory.cs:line 114
         at Microsoft.SemanticKernel.Memory.SemanticTextMemory.SearchAsync(String collection, String query, Int32 limit, Double minRelevanceScore, Boolean withEmbeddings, CancellationToken cancellationToken)+MoveNext() in D:\MyGitHub\semantic-kernel@microshaoft-Debug\dotnet\src\SemanticKernel\Memory\SemanticTextMemory.cs:line 114
         at Microsoft.SemanticKernel.Memory.SemanticTextMemory.SearchAsync(String collection, String query, Int32 limit, Double minRelevanceScore, Boolean withEmbeddings, CancellationToken cancellationToken)+System.Threading.Tasks.Sources.IValueTaskSource<System.Boolean>.GetResult()
         at CopilotChat.WebApi.Skills.ChatSkills.SemanticChatMemorySkill.QueryMemoriesAsync(String query, String chatId, Int32 tokenLimit, ISemanticTextMemory textMemory) in D:\MyGitHub\semantic-kernel@microshaoft-Debug\chat-copilot\webapi\Skills\ChatSkills\SemanticChatMemorySkill.cs:line 78
         at CopilotChat.WebApi.Skills.ChatSkills.SemanticChatMemorySkill.QueryMemoriesAsync(String query, String chatId, Int32 tokenLimit, ISemanticTextMemory textMemory) in D:\MyGitHub\semantic-kernel@microshaoft-Debug\chat-copilot\webapi\Skills\ChatSkills\SemanticChatMemorySkill.cs:line 78
         at CopilotChat.WebApi.Skills.ChatSkills.ChatSkill.GetChatResponseAsync(String chatId, String userId, SKContext chatContext, CancellationToken cancellationToken) in D:\MyGitHub\semantic-kernel@microshaoft-Debug\chat-copilot\webapi\Skills\ChatSkills\ChatSkill.cs:line 377
         at CopilotChat.WebApi.Skills.ChatSkills.ChatSkill.ChatAsync(String message, String userId, String userName, String chatId, String messageType, String planJson, String messageId, SKContext context, CancellationToken cancellationToken) in D:\MyGitHub\semantic-kernel@microshaoft-Debug\chat-copilot\webapi\Skills\ChatSkills\ChatSkill.cs:line 299         at Microsoft.SemanticKernel.SkillDefinition.NativeFunction.InvokeAsync(SKContext context, CompleteRequestSettings settings, CancellationToken cancellationToken) in D:\MyGitHub\semantic-kernel@microshaoft-Debug\dotnet\src\SemanticKernel\SkillDefinition\NativeFunction.cs:line 165
        Exception data:
          Severity: ERROR
          SqlState: 42P01
          MessageText: relation "public.d8ff415b-167b-4b1a-8dd8-7d62f97f120d-LongTermMemory" does not exist
          Position: 115
          File: parse_relation.c
          Line: 1371
          Routine: parserOpenTable

Expected behavior
A clear and concise description of what you expected to happen.

  1. before searching , the memorystore related collection should be create at first
  2. The method of CreateCollectionAsync belongs Other implemention of IMemoryStore (such as QdrantMemoryStore and VolatileMemoryStore) can be invoked properly, but PostgresMemoryStore's CreateCollectionAsync method have never been invoked when use local Postgresql as memorystore.

Screenshots
If applicable, add screenshots to help explain your problem.

  1. error when search vector in PostgresMemoryStore, but maybe it's not root cause
    image

  2. For reference, the below code is in Connectors.Memory.Postgres project , it belongs to Semantic-Kernel, not belong to chat-copilot
    I have debugged chat-copilot and semantic-kernel code ,I can't break in the break points in below screenshot:
    image

Platform

  • OS: windows 11
  • IDE: Visual Studio 2022, VS Code
  • Language: C#
  • Source: [e.g. NuGet package version 0.1.0, pip package version 0.1.0, main branch of repository]

Additional context
Add any other context about the problem here.

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingexternal dependency issueIssues related to external dependencies (e.g. Azure)memoryIssues or questions related to memorywebapiPull requests that update .net code

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions