mirror of
https://github.com/langchain-ai/langchain-postgres.git
synced 2026-07-16 01:33:18 -04:00
[PR #32] [CLOSED] Add async mode for pgvector #130
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/langchain-ai/langchain-postgres/pull/32
Author: @pprados
Created: 4/22/2024
Status: ❌ Closed
Base:
main← Head:pprados/async📝 Commits (10+)
188c83dPre integration PPR69c22a3Add async mode0abd730Fix linte1ad8c8It's possible to share the session_maker with sync mode.dc6187aFix apost_init14d6da8Add async APIe95df2fRebase9c2035cFix create_vector_extension with async7cc0bb1Fix create_vector_extension with async4cbeeb2Re-ajuste les UI vis à vis de l'async (partiellement)📊 Changes
3 files changed (+1326 additions, -85 deletions)
View changed files
📝
langchain_postgres/vectorstores.py(+828 -72)📝
pyproject.toml(+4 -0)📝
tests/unit_tests/test_vectorstore.py(+494 -13)📄 Description
This PR adds the async approach for pgvector.
Some remarks:
remove these checks with
python -O ...session_makerattribute. 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
SQLRecordManagerand 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
SQLRecordManagerandPGVectoras 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_makerof
SQLRecordManagerandPGVector, 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.pyin
_amake_session()must first be fixed (See PR ).Then, it is possible to do the same thing asynchronously:
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.