Skip to content

Commit

Permalink
chore: Use psycopg2.extras.execute_values for batch insert in PGVector
Browse files Browse the repository at this point in the history
  • Loading branch information
vaayne committed May 5, 2024
1 parent a932466 commit 86cb30d
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions api/core/rag/datasource/vdb/pgvector/pgvector.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from contextlib import contextmanager
from typing import Any

import psycopg2.extras
import psycopg2.pool
from pydantic import BaseModel

Expand Down Expand Up @@ -80,8 +81,8 @@ def add_texts(self, documents: list[Document], embeddings: list[list[float]], **
)
)
with self._get_cursor() as cur:
cur.executemany(
f"INSERT INTO {self.table_name} (id, text, meta, embedding) VALUES (%s, %s, %s, %s)", values
psycopg2.extras.execute_values(
cur, f"INSERT INTO {self.table_name} (id, text, meta, embedding) VALUES %s", values
)
return pks

Expand Down

0 comments on commit 86cb30d

Please sign in to comment.