refactor(api): use sessionmaker in pgvecto_rs VDB service#34818
Conversation
Pyrefly Diffbase → PR--- /tmp/pyrefly_base.txt 2026-04-09 05:39:42.968336153 +0000
+++ /tmp/pyrefly_pr.txt 2026-04-09 05:39:34.492282664 +0000
@@ -163,7 +163,7 @@
ERROR Function declared to return `bool`, but one or more paths are missing an explicit `return` [bad-return]
--> core/rag/datasource/vdb/oracle/oraclevector.py:191:39
ERROR No matching overload found for function `sqlalchemy.sql.sqltypes.UUID.__init__` called with arguments: (as_uuid=Literal[True]) [no-matching-overload]
- --> core/rag/datasource/vdb/pgvecto_rs/pgvecto_rs.py:67:32
+ --> core/rag/datasource/vdb/pgvecto_rs/pgvecto_rs.py:66:32
ERROR Argument `str | None` is not assignable to parameter `database_name` with type `str` in function `tcvectordb.rpc.client.stub.RPCVectorDBClient.describe_collection` [bad-argument-type]
--> core/rag/datasource/vdb/tencent/tencent_vector.py:82:35
ERROR Object of class `FilterIndex` has no attribute `dimension`
|
There was a problem hiding this comment.
Pull request overview
Refactors the PGVectoRS vector DB service’s write transactions to use SQLAlchemy’s sessionmaker(...).begin() context manager, aligning writes with transactional scope semantics and removing explicit commit() calls. This is part of the broader effort in #24245.
Changes:
- Replaced multiple
with Session(engine)+commit()write blocks withwith sessionmaker(bind=engine).begin()in the PGVectoRS service. - Kept read-only session usage unchanged.
- Updated unit tests to patch both
Sessionandsessionmakerto match the new transaction pattern.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
api/core/rag/datasource/vdb/pgvecto_rs/pgvecto_rs.py |
Uses sessionmaker(...).begin() for write transactions; removes explicit commits. |
api/tests/unit_tests/core/rag/datasource/vdb/pgvecto_rs/test_pgvecto_rs.py |
Adds test helpers/mocks for sessionmaker().begin() and patches both session entrypoints. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| self._client = create_engine(self._url) | ||
| with Session(self._client) as session: | ||
| with sessionmaker(bind=self._client).begin() as session: | ||
| session.execute(text("CREATE EXTENSION IF NOT EXISTS vectors")) | ||
| session.commit() | ||
| self._fields: list[str] = [] |
There was a problem hiding this comment.
sessionmaker(bind=self._client) is instantiated inline in multiple methods. Consider creating a single session factory in __init__ (e.g., self._sessionmaker = sessionmaker(bind=self._client)) and then using with self._sessionmaker.begin() as session: everywhere to reduce duplication and make future configuration/testing simpler.
|
@asukaminato0721 Thank you very much. |
Summary
with Session(self._client)+session.commit()withsessionmaker(bind=self._client).begin()in pgvecto_rs VDB service (6 blocks)Part of #24245
Test plan
ruff checkpasses