-
Notifications
You must be signed in to change notification settings - Fork 56
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
Add async mode for pgvector (v2) #64
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I made the mistake of doing a rebase while a review was in progress. This seems to block the process. There's a ‘1 change requested’ request that I can't validate. I propose another PR identical to the previous one.
This PR adds the async approach for pgvector.
Some remarks:
remove these checks with
python -O ...
session_maker
attribute. This is very important for resilientscenarios.
In a RAG architecture, it is necessary to import document chunks.
To keep track of the links between chunks and documents, we can use the
index() API.
This API proposes to use an SQL-type record manager.
In a classic use case, using
SQLRecordManager
and a vector database, it is impossibleto guarantee the consistency of the import.
Indeed, if a crash occurs during the import, there is an inconsistency between the SQL
database and the vector database.
PGVector is the solution to this problem.
Indeed, it is possible to use a single database (and not a two-phase commit with 2
technologies, if they are both compatible). But, for this, it is necessary to be able
to combine the transactions between the use of
SQLRecordManager
andPGVector
as avector database.
This is only possible if it is possible to intervene on the
session_maker
.This is why we propose to make this attribute public. By unifying the
session_maker
of
SQLRecordManager
andPGVector
, it is possible to guarantee that all processes willbe executed in a single transaction.
This is, moreover, the only solution we know of to guarantee the consistency of the
import of chunks into a vector database. It's possible only if the outer session is built
with the connection.
The same thing is possible asynchronously, but a bug in
sql_record_manager.py
in
_amake_session()
must first be fixed (See PR ).Then, it is possible to do the same thing asynchronously:
The promise of the constructor, with the
create_extension
parameter, is to guarantee that the extension is added before the APIs are used. Since this promise cannot be kept in anasync
scenario, there is an alternative:async
method is needed to install the extension before the APIs are used, and to check that this method has been invoked at the start of each API.