Skip to content

.Net: Bug: Postgres Connector create Index failed #10521

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

Closed
JadynWong opened this issue Feb 13, 2025 · 0 comments · Fixed by #10529
Closed

.Net: Bug: Postgres Connector create Index failed #10521

JadynWong opened this issue Feb 13, 2025 · 0 comments · Fixed by #10529
Assignees
Labels
bug Something isn't working .NET Issue or Pull requests regarding .NET code

Comments

@JadynWong
Copy link
Contributor

Describe the bug
If the name of the collection contains ‘-’ it will fail to be created, throwing the following exception.

42601: syntax error at or near "-"

POSITION: 33

To Reproduce
Execute the following code in a database with the pgvector extension enabled

#pragma warning disable SKEXP0020

var kernelBuilder = Kernel.CreateBuilder();
kernelBuilder.Services.AddPostgresVectorStore("XXXXX");

var kernel = kernelBuilder.Build();

var _vectorStore = kernel.GetRequiredService<IVectorStore>();

var vectorStoreRecordCollection = _vectorStore.GetCollection<string, KnowledgeRecord>("KR-1");
await vectorStoreRecordCollection.CreateCollectionIfNotExistsAsync();

Expected behavior
Collections can be created successfully even if their name contains ‘-’.

Platform

  • Language: C#
  • Source: Microsoft.SemanticKernel.Connectors.Postgres v1.37.0-alpha
  • AI model: OpenAI:text-embedding-3-large
  • IDE: Visual Studio
  • OS: Windows

Additional context

indexName needs to be wrapped in double quotes.

var indexName = $"{tableName}_{vectorColumnName}_index";
return new PostgresSqlCommandInfo(
commandText: $@"
CREATE INDEX {indexName} ON {schema}.""{tableName}"" USING {indexTypeName} (""{vectorColumnName}"" {indexOps});"
);

@JadynWong JadynWong added the bug Something isn't working label Feb 13, 2025
@markwallace-microsoft markwallace-microsoft added .NET Issue or Pull requests regarding .NET code triage labels Feb 13, 2025
github-merge-queue bot pushed a commit that referenced this issue Feb 13, 2025
…tion. (#10529)

### Motivation and Context

Fixes #10521

### Description

- Wrap index name in double quotes to handle special characters in
collection names
- Add integration test to verify fix.
- Fix unrelated flaky integration test

### Contribution Checklist

<!-- Before submitting this PR, please make sure: -->

- [x] The code builds clean without any errors or warnings
- [x] The PR follows the [SK Contribution
Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md)
and the [pre-submission formatting
script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts)
raises no violations
- [x] All unit tests pass, and I have added new tests where possible
- [x] I didn't break anyone 😄
@westey-m westey-m moved this from Bug to Sprint: Done in Semantic Kernel Feb 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working .NET Issue or Pull requests regarding .NET code
Projects
Archived in project
3 participants