Langchain PGVector is not working is not able to call the sql alchemy in vectorstore.py (missing package error) #21748
Labels
🤖:bug
Related to a bug, vulnerability, unexpected error with an existing feature
🔌: postgres
Related to postgres integrations
Ɑ: vector store
Related to vector store module
Checked other resources
Example Code
import psycopg2
from langchain_postgres.vectorstores import PGVector
from langchain_community.document_loaders import TextLoader
from langchain.text_splitter import RecursiveCharacterTextSplitter
from langchain_community.embeddings import GooglePalmEmbeddings
from langchain_google_genai import GoogleGenerativeAI
from langchain_core.documents import Document
from langchain_postgres import PGVector
from langchain_postgres.vectorstores import PGVector
from langchain_community.vectorstores import pgvector
import pgvector
from pgvector.sqlalchemy import Vector
loader=TextLoader("/home/sambasiva/dev/fastapi-template/src/api/embedding_transformer/timeline.txt",encoding="utf8")
documents=loader.load()
text_splitter = RecursiveCharacterTextSplitter(chunk_size=1000, chunk_overlap=20)
chunks = text_splitter.split_documents(documents)
embeddings = GooglePalmEmbeddings(google_api_key=API)
connection = "postgresql+psycopg://vectorapi:vectorapipass@localhost:5432/vectordb"
collection_name = "my_docs"
db=PGVector.from_documents(embedding=embeddings,documents=chunks, collection_name=collection_name,connection=connection,)
print(len(chunks))
try:
conn = psycopg2.connect(
dbname="vectordb",
user="vectorapi",
password="vectorapipass",
host="localhost", # Optional, defaults to localhost
port="5432" # Optional, defaults to 5432
)
print("Connection successful!")
except Exception as e:
print(f"Error connecting to database: {e}")
Error Message and Stack Trace (if applicable)
sambasiva@USLDMJTG24:~/dev/fastapi-template$ /bin/python3 /home/sambasiva/dev/fastapi-template/src/api/embedding_transformer/test.py
Traceback (most recent call last):
File "/home/sambasiva/dev/fastapi-template/src/api/embedding_transformer/test.py", line 25, in
db=PGVector.from_documents(embedding=embeddings,documents=chunks, collection_name=collection_name,connection=connection,)
File "/home/sambasiva/.local/lib/python3.10/site-packages/langchain_postgres/vectorstores.py", line 1107, in from_documents
return cls.from_texts(
File "/home/sambasiva/.local/lib/python3.10/site-packages/langchain_postgres/vectorstores.py", line 975, in from_texts
return cls.__from(
File "/home/sambasiva/.local/lib/python3.10/site-packages/langchain_postgres/vectorstores.py", line 438, in __from
store = cls(
File "/home/sambasiva/.local/lib/python3.10/site-packages/langchain_postgres/vectorstores.py", line 308, in init
self.post_init()
File "/home/sambasiva/.local/lib/python3.10/site-packages/langchain_postgres/vectorstores.py", line 317, in post_init
EmbeddingStore, CollectionStore = _get_embedding_collection_store(
File "/home/sambasiva/.local/lib/python3.10/site-packages/langchain_postgres/vectorstores.py", line 91, in _get_embedding_collection_store
from pgvector.sqlalchemy import Vector # type: ignore
ModuleNotFoundError: No module named 'pgvector.sqlalchemy'; 'pgvector' is not a package
Description
I am trying to use the langchain library to perform a RAG application but while using the pgvector as a database i encountered th issue with the langchain package langchain_postgres/vectorstores.py
in which it is giving the error of module not found and that pgvector is not a package
System Info
langchain==0.1.19
langchain-community==0.0.38
langchain-core==0.1.52
langchain-google-genai==1.0.3
langchain-google-vertexai==1.0.3
langchain-postgres==0.0.4
langchain-text-splitters==0.0.1
platform windows
python version= 3.11
The text was updated successfully, but these errors were encountered: