semantic-kernel icon indicating copy to clipboard operation
semantic-kernel copied to clipboard

Qdrant (and other memory stores?) - support rigid filtering

Open piotrek-appstream opened this issue 2 years ago • 2 comments

I have structured and unstructured data that I need to search using both vector similarity and structured data filtering. Qdrant supports payload filtering alongside vector similarity (as far as I know, Pinecone does as well), but the IMemoryStore interface does not currently support it.

What do you think would be the best way to address this issue?

  • Support rigid filtering through the IMemoryStore interface. I'm willing to work on this if it's decided that this is the approach to take.
  • Create my own class that inherits from QdrantVectorDbClient (or just copy it) and extends the base class with methods that support rigid filtering. I would then use this extended class explicitly in a skill.
  • Is there another recommended approach?

Thank you in advance. P.S. This library is really cool! 👌

piotrek-appstream avatar May 25 '23 12:05 piotrek-appstream

@piotrek-appstream , great idea! @awharrison-28 and @tawalke does this look like the right approach?

evchaki avatar May 25 '23 20:05 evchaki

I agree that there is value in integrating semantic search capabilities with filtering functionalities for the structured segment of data. However, simply extending IMemoryStore may not be sufficient. Currently, it is not exposed either through SkContext or SemanticKernel, correct?

I was thinking about a solution that would allow us to use it seamlessly within the skill, just through context.Memory. What are your thoughts on the following options:

  • Extending ISemanticTextMemory with the following method:
public IAsyncEnumerable<MemoryQueryResult> SearchStructuredAsync(
       string collection,
       string query,
       int limit = 1,
       double minRelevanceScore = 0.7,
       bool withEmbeddings = false,
       IFilterExpression? filters = default, // some kind of expression to filter by payload fields
       CancellationToken cancellationToken = default)

This way, in the skill, we can simply use context.Memory.SearchStructuredAsync.

  • Introducing a new interface, ISemanticStructuredMemory, specifically designed for partially structured memories. It could be configured using .WithStructuredMemoryStorage(...) and utilized in the skill as context.StructuredMemory. I understand this option may require more effort, but it would allow us to tailor methods like SaveInformation or SaveReference in the new interface to better suit partially structured data.

lukasz-appstream avatar May 26 '23 08:05 lukasz-appstream

@evchaki we have a PR ready for that, first with Qdrant, but designed in a way to be extendible for other memory stores without limiting their capabilities (source specific generic filter argument).

Would appreciate to get some feedback :)

Thanks!

lukasz-appstream avatar Jun 15 '23 08:06 lukasz-appstream

All .Net issues prior to 1-Dec-2023 are being closed. Please re-open, if this issue is still relevant to the .Net Semantic Kernel 1.x release. In the future all issues that are inactive for more than 90 days will be labelled as 'stale' and closed 14 days later.

markwallace-microsoft avatar Mar 12 '24 16:03 markwallace-microsoft