Skip to content
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

Bug: Plugin created by VectorStoreTextSearch.CreateWithGetTextSearchResults is not returning the results from the IVectorStore #9762

Closed
thomashauser opened this issue Nov 19, 2024 · 4 comments
Assignees
Labels
bug Something isn't working .NET Issue or Pull requests regarding .NET code

Comments

@thomashauser
Copy link

thomashauser commented Nov 19, 2024

Describe the bug
The method VectorizableTextSearchAsync is returning to document chunks, but the plugin said it is empty.

To Reproduce
ITextEmbeddingGenerationService textEmbeddingGenerationService = new OpenAITextEmbeddingGenerationService("text-embedding-small", openAiClient);
IVectorStore vectorStore = new SqlServerVectorStore(connectionString)
.UseTextEmbeddingGenerationService(textEmbeddingGenerationService);

var globalVectorStoreRecordCollection = vectorStore.GetCollection<int, DocumentRecord>("Global");
await globalVectorStoreRecordCollection.CreateCollectionIfNotExistsAsync();
var chatVectorStoreRecordCollection = vectorStore.GetCollection<int, DocumentRecord>($"Chat{chatId}");
await chatVectorStoreRecordCollection.CreateCollectionIfNotExistsAsync();

var globalSearch = new VectorStoreTextSearch(globalVectorStoreRecordCollection, textEmbeddingGenerationService);
var chatSearch = new VectorStoreTextSearch(chatVectorStoreRecordCollection, textEmbeddingGenerationService);

var builder = Kernel.CreateBuilder();
builder.AddAzureOpenAIChatCompletion(MODEL, azureOpenAIClient: openAiClient);
builder.Services.AddLogging(services => services.AddConsole().SetMinimumLevel(LogLevel.Trace));

var kernel = builder.Build();

// Add the plugin to the kernel
kernel.Plugins.Add(globalSearch.CreateWithGetTextSearchResults(nameof(globalSearch)));
kernel.Plugins.Add(chatSearch.CreateWithGetTextSearchResults(nameof(chatSearch)));

// Retrieve the chat completion service
var chatCompletionService = kernel.Services.GetRequiredService();

Expected behavior
The kernel should receive the two found document chunks.

Screenshots
Image
Image

Platform

  • OS: Windows
  • IDE: Visual Studio 2022 17.12.0
  • Language: C#
  • Azure OpenAI: gpt-4o (2024-08-06), text-embedding-3-small
  • Source:
    Azure.AI.DocumentIntelligence: 1.0.0-beta.3
    Microsoft.Extensions.Configuration.Json: 9.0.0
    Microsoft.Extensions.Configuration.UserSecrets: 9.0.0
    Microsoft.Extensions.DependencyInjection: 9.0.0
    Microsoft.Extensions.Logging.Console: 9.0.0
    Microsoft.Extensions.VectorData.Abstractions: 9.0.0-preview.1.24523.1
    Microsoft.SemanticKernel: 1.29.0
    Microsoft.SemanticKernel.Connectors.SqlServer: 1.29.0-alpha
    Microsoft.SemanticKernel.Plugins.Core: 1.29.0-alpha
    Microsoft.SemanticKernel.Plugins.Document: 1.29.0-alpha
    Microsoft.SemanticKernel.Plugins.Memory: 1.29.0-alpha
    Microsoft.Data.SqlClient: 5.2.2
    Microsoft.SemanticKernel.Abstractions: 1.29.0
    Microsoft.SemanticKernel.Connectors.AzureOpenAI: 1.29.0
    Microsoft.SemanticKernel.Connectors.OpenAI: 1.29.0
    System.Linq.Async: 6.0.1
@thomashauser thomashauser added the bug Something isn't working label Nov 19, 2024
@markwallace-microsoft markwallace-microsoft added .NET Issue or Pull requests regarding .NET code triage labels Nov 19, 2024
@github-actions github-actions bot changed the title Bug: .Net: Bug: Nov 19, 2024
@thomashauser thomashauser changed the title .Net: Bug: Bug: Plugin created by VectorStoreTextSearch.CreateWithGetTextSearchResults is not returning the results from the IVectorStore Nov 19, 2024
@markwallace-microsoft markwallace-microsoft self-assigned this Nov 19, 2024
@markwallace-microsoft markwallace-microsoft moved this to Sprint: In Progress in Semantic Kernel Nov 19, 2024
@markwallace-microsoft
Copy link
Member

Hi @thomashauser
we have this sample VectorStore_TextSearch.cs which shows this working with our in-memory store. Can you reproduce the error by changing this sample?

Did you create your own SqlServerVectorStore implementation?

@inQuantum
Copy link

Objects from VectorSearch Results should be transformed/mapped to TextSearchResult. This should solve issue.

var result = new VectorStoreTextSearch<DataModel>(vectorStoreRecordCollection, textEmbeddingGeneration, stringMapper, resultMapper);


protected sealed class DataModelTextSearchStringMapper : ITextSearchStringMapper
{
    /// <inheritdoc />
    public string MapFromResultToString(object result)
    {
        if (result is DataModel dataModel)
        {
            return dataModel.Text;
        }
        throw new ArgumentException("Invalid result type.");
    }
}

/// <summary>
/// Result mapper which converts a DataModel to a TextSearchResult.
/// </summary>
protected sealed class DataModelTextSearchResultMapper : ITextSearchResultMapper
{
    /// <inheritdoc />
    public TextSearchResult MapFromResultToTextSearchResult(object result)
    {
        if (result is DataModel dataModel)
        {
            return new TextSearchResult(value: dataModel.Text) { Name = dataModel.Key.ToString(), Link = dataModel.Link };
        }
        throw new ArgumentException("Invalid result type.");
    }
}

@thomashauser
Copy link
Author

Hi @thomashauser
we have this sample VectorStore_TextSearch.cs which shows this working with our in-memory store. Can you reproduce the error by changing this sample?

Did you create your own SqlServerVectorStore implementation?

Yes, it's my own implementation. There is currently no version that supports IVectoreStore and not the deprecated kernel memory, right?

@thomashauser
Copy link
Author

Objects from VectorSearch Results should be transformed/mapped to TextSearchResult. This should solve issue.

var result = new VectorStoreTextSearch<DataModel>(vectorStoreRecordCollection, textEmbeddingGeneration, stringMapper, resultMapper);


protected sealed class DataModelTextSearchStringMapper : ITextSearchStringMapper
{
    /// <inheritdoc />
    public string MapFromResultToString(object result)
    {
        if (result is DataModel dataModel)
        {
            return dataModel.Text;
        }
        throw new ArgumentException("Invalid result type.");
    }
}

/// <summary>
/// Result mapper which converts a DataModel to a TextSearchResult.
/// </summary>
protected sealed class DataModelTextSearchResultMapper : ITextSearchResultMapper
{
    /// <inheritdoc />
    public TextSearchResult MapFromResultToTextSearchResult(object result)
    {
        if (result is DataModel dataModel)
        {
            return new TextSearchResult(value: dataModel.Text) { Name = dataModel.Key.ToString(), Link = dataModel.Link };
        }
        throw new ArgumentException("Invalid result type.");
    }
}

Awesome that worked. Thanks

@github-project-automation github-project-automation bot moved this from Sprint: In Review to Sprint: Done in Semantic Kernel Nov 25, 2024
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
Status: Sprint: Done
Development

No branches or pull requests

3 participants