Skip to content

Commit

Permalink
pgvector
Browse files Browse the repository at this point in the history
  • Loading branch information
efriis committed Dec 7, 2023
1 parent f3e61d8 commit 358fafe
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions libs/langchain/langchain/vectorstores/_pgvector_data_models.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
from typing import Optional, Tuple
from typing import TYPE_CHECKING, Optional, Tuple

import sqlalchemy
from pgvector.sqlalchemy import Vector
from sqlalchemy.dialects.postgresql import JSON, UUID
from sqlalchemy.orm import Session, relationship

from langchain.vectorstores.pgvector import BaseModel

if TYPE_CHECKING:
from pgvector.sqlalchemy import Vector


def _import_vector() -> None:
try:
from pgvector.sqlalchemy import Vector
except ImportError:
raise ImportError(
"The `pgvector` library is required to use the PGVectorStore."
)
return Vector


class CollectionStore(BaseModel):
"""Collection store."""
Expand Down Expand Up @@ -63,7 +75,7 @@ class EmbeddingStore(BaseModel):
)
collection = relationship(CollectionStore, back_populates="embeddings")

embedding: Vector = sqlalchemy.Column(Vector(None))
embedding: Vector = sqlalchemy.Column(_import_vector()(None))
document = sqlalchemy.Column(sqlalchemy.String, nullable=True)
cmetadata = sqlalchemy.Column(JSON, nullable=True)

Expand Down

0 comments on commit 358fafe

Please sign in to comment.