Skip to content

.Net MEVD: Clarify thread-safety of the abstraction #10454

Closed

Description

@roji

Most implementation of the abstraction provide thread-safety, i.e. the instances of IVectorStore and IVectorStoreRecordCollection can be used concurrently from multiple threads; but not all.

  1. PostgresVectorStoreRecordCollection accepts an NpgsqlDataSource, and gets a new (pooled) connection for aech operation. This is a thread-safe design, where multiple threads can use PostgresVectorStoreRecordCollection concurrently.
  2. In contrast, SqliteVectorStoreRecordCollection gets initialized with a DbConnection, which is not a thread-safe object.

IMHO we should be guaranteeing thread-safety, and fix the SQLite implementation to e.g. accept a connection string (or DbDataSource) instead of a DbConnection.

Activity

  1. dmytrostruk commented on Feb 9, 2025

    @dmytrostruk
    Member

    I'm wondering, if we change SQLite implementation to accept a connection string, it means that we will have to create a new instance of DbConnection on our side. It will probably force us to make SqliteVectorStoreRecordCollection as IDisposable. I don't think it's a problem, but it won't be aligned with other connectors. However, thread-safety would be more important than API alignment.

    If we do that, does it mean that we won't recommend registering SqliteVectorStoreRecordCollection as Singleton in user applications to avoid long-lived connections?

  2. roji commented on Feb 9, 2025

    @roji
    MemberAuthor

    It will probably force us to make SqliteVectorStoreRecordCollection as IDisposable

    I'm not sure - I was thinking we'd create (and open) a new SqliteConnection for each operation. After all, that's what the PostgreSQL provider does too - it just does it via NpgsqlDataSource.

  3. dmytrostruk commented on Feb 9, 2025

    @dmytrostruk
    Member

    I'm not sure - I was thinking we'd create (and open) a new SqliteConnection for each operation.

    In that case we should be good. I didn't know about the existence of DbDataSource. If it's working with SQLite, then I guess it should be a good choice.

  4. added
    sk team issueA tag to denote issues that where created by the Semantic Kernel team (i.e., not the community)
    on Feb 10, 2025
  5. added 3 commits that reference this issue on Feb 14, 2025
    ccc3332
    11a1dc2
    36342b4
  6. added 2 commits that reference this issue on Mar 14, 2025
    d3014b9
    ce572c8
  7. added a commit that references this issue on Mar 14, 2025
    036fe89
  8. roji commented on Mar 14, 2025

    @roji
    MemberAuthor

    The Sqlite connector has been fixed to be thread-safe (#10972, accept connection string instead of DbConnection), Adam Sitnik (@adamsitnik) we need to do the same for the new SQL Server connector.

    Beyond that we should add docs to IVectorStore/IVectorStoreRecordCollection to reflect that they're thread-safe unless otherwise documented (#10991).

  9. added a commit that references this issue on Mar 17, 2025
    89aab09
  10. moved this from Sprint: Done to Backlog: Planned in Semantic Kernelon Mar 19, 2025
  11. markwallace-microsoft commented on Mar 19, 2025

    @markwallace-microsoft
    Contributor

    Only documentation is remaining

  12. moved this from Backlog: Planned to Sprint: Done in Semantic Kernelon May 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions