- 
                Notifications
    You must be signed in to change notification settings 
- Fork 394
Description
Context / Scenario
I'm developing a .NET console application that uses KernelMemory to manage and search documents. My setup involves multiple indexes stored in a SQL Server 2025 database.
What happened?
When I perform a search targeting a specific index, the query unexpectedly returns results from other, unrelated indexes. This behavior is inconsistent with other storage backends (e.g., Azure AI Search), which correctly restrict the search to the specified index.
As an example, I have included a minimal, reproducible code snippet below that demonstrates the problem:
using Microsoft.KernelMemory;
using Microsoft.KernelMemory.AI;
using Microsoft.KernelMemory.MemoryDb.SQLServer;
using System.Text.Json;
var KMClient = new KernelMemoryBuilder()
    .WithAzureOpenAITextGeneration(new()
    {
        Auth = AzureOpenAIConfig.AuthTypes.APIKey,
        Endpoint = "AZURE OPENAI ENDPOINT",
        APIKey = "AZURE OPENAI KEY",
        APIType = AzureOpenAIConfig.APITypes.ChatCompletion,
        Deployment = "gpt-4o-mini",
        MaxTokenTotal = 128000
    })
    .WithAzureOpenAITextEmbeddingGeneration
    (
        new()
        {
            Auth = AzureOpenAIConfig.AuthTypes.APIKey,
            Endpoint = "AZURE OPENAI ENDPOINT",
            APIKey = "AZURE OPENAI KEY",
            APIType = AzureOpenAIConfig.APITypes.EmbeddingGeneration,
            Deployment = "text-embedding-ada-002",
            MaxTokenTotal = 8191
        },
        new GPT4oTokenizer()
    )
    .WithSqlServerMemoryDb(new SqlServerConfig { UseNativeVectorSearch = true, ConnectionString = "SQL SERVER CONNECTION STRING" })
    .WithSearchClientConfig(new() { EmptyAnswer = "I don't know", Temperature = 0 })
    .Build<MemoryServerless>(new KernelMemoryBuilderBuildOptions { AllowMixingVolatileAndPersistentData = true });
await KMClient.ImportTextAsync("My cat's name is Bob.", documentId: "index-A-1", index: "index-A");
await KMClient.ImportTextAsync("My cat's name is Luna.", documentId: "index-B-1", index: "index-B");
SearchResult response = await KMClient.SearchAsync("What is my cat's name?", "index-A");
string jsonFormated = JsonSerializer.Serialize(response.Results, new JsonSerializerOptions { WriteIndented = true });
Console.WriteLine(jsonFormated);
This code snippet aims to:
- Create two distinct indexes: index-A' and 'index-B'.
- Import a document into each index.
 
- Perform a search specifically on 'index-A'.
Expected Output:
The search should only return the document from 'index-A' ("My cat's name is Bob.").
Actual Output:
The search returns results from both 'index-A' and 'index-B', indicating a cross-index search.
[
  {
    "link": "index-A/index-A-1/1841bb3d19c643d3b374a929a8b24c0c",
    "index": "index-A",
    "documentId": "index-A-1",
    "fileId": "1841bb3d19c643d3b374a929a8b24c0c",
    "sourceContentType": "text/plain",
    "sourceName": "content.txt",
    "sourceUrl": "/download?index=index-A\u0026documentId=index-A-1\u0026filename=content.txt",
    "partitions": [
      {
        "text": "My cat\u0027s name is Bob.",
        "relevance": 0.8990762,
        "partitionNumber": 0,
        "sectionNumber": 0,
        "lastUpdate": "2025-08-20T18:10:47+00:00",
        "tags": {
          "__document_id": [
            "index-A-1"
          ],
          "__file_type": [
            "text/plain"
          ],
          "__file_id": [
            "1841bb3d19c643d3b374a929a8b24c0c"
          ],
          "__file_part": [
            "d53b0e9169424f7b94ea9bce88c2f8bb"
          ],
          "__part_n": [
            "0"
          ],
          "__sect_n": [
            "0"
          ]
        }
      }
    ]
  },
  {
    "link": "index-A/index-B-1/1a269aa2ae034f7f82f1e4f59953d65e",
    "index": "index-A",
    "documentId": "index-B-1",
    "fileId": "1a269aa2ae034f7f82f1e4f59953d65e",
    "sourceContentType": "text/plain",
    "sourceName": "content.txt",
    "sourceUrl": "/download?index=index-A\u0026documentId=index-B-1\u0026filename=content.txt",
    "partitions": [
      {
        "text": "My cat\u0027s name is Luna.",
        "relevance": 0.89873284,
        "partitionNumber": 0,
        "sectionNumber": 0,
        "lastUpdate": "2025-08-20T18:10:48+00:00",
        "tags": {
          "__document_id": [
            "index-B-1"
          ],
          "__file_type": [
            "text/plain"
          ],
          "__file_id": [
            "1a269aa2ae034f7f82f1e4f59953d65e"
          ],
          "__file_part": [
            "57bd3fba6be94976bb848a36a61b2bbd"
          ],
          "__part_n": [
            "0"
          ],
          "__sect_n": [
            "0"
          ]
        }
      }
    ]
  }
]
Importance
a fix would make my life easier
Platform, Language, Versions
- C# (.NET 8.0)
- KernelMemory: 0.98.250508.3 (running in serverless mode)
- Microsoft SQL Server 2025 (CTP2.0) - 17.0.700.9 (X64)