Skip to content

Commit

Permalink
Support unique node_id for postgresql (#236)
Browse files Browse the repository at this point in the history
  • Loading branch information
zt2645802240 authored Sep 27, 2024
1 parent b2d2b13 commit 648277a
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/pai_rag/integrations/vector_stores/postgresql/postgresql.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class HybridAbstractData(base): # type: ignore
id = Column(BIGINT, primary_key=True, autoincrement=True)
text = Column(VARCHAR, nullable=False)
metadata_ = Column(metadata_dtype)
node_id = Column(VARCHAR)
node_id = Column(VARCHAR, unique=True)
embedding = Column(Vector(embed_dim)) # type: ignore
text_search_tsv = Column( # type: ignore
TSVector(),
Expand All @@ -98,7 +98,7 @@ class AbstractData(base): # type: ignore
id = Column(BIGINT, primary_key=True, autoincrement=True)
text = Column(VARCHAR, nullable=False)
metadata_ = Column(metadata_dtype)
node_id = Column(VARCHAR)
node_id = Column(VARCHAR, unique=True)
embedding = Column(Vector(embed_dim)) # type: ignore

model = type(
Expand Down Expand Up @@ -398,7 +398,13 @@ def add(self, nodes: List[BaseNode], **add_kwargs: Any) -> List[str]:
self._initialize()
ids = []
with self._session() as session, session.begin():
from sqlalchemy import delete

for node in nodes:
stmt = delete(self._table_class).where(
self._table_class.node_id == node.node_id
)
session.execute(stmt)
ids.append(node.node_id)
item = self._node_to_table_row(node)
session.add(item)
Expand Down

0 comments on commit 648277a

Please sign in to comment.