Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Langchain PGVector is not working is not able to call the sql alchemy in vectorstore.py (missing package error) #21748

Open
5 tasks done
sambasivaj24 opened this issue May 16, 2024 · 2 comments
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

Comments

@sambasivaj24
Copy link

Checked other resources

  • I added a very descriptive title to this issue.
  • I searched the LangChain documentation with the integrated search.
  • I used the GitHub search to find a similar question and didn't find it.
  • I am sure that this is a bug in LangChain rather than my code.
  • The bug is not resolved by updating to the latest stable version of LangChain (or the specific integration package).

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

@dosubot dosubot bot added Ɑ: vector store Related to vector store module 🔌: postgres Related to postgres integrations 🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature labels May 16, 2024
@maximeperrindev
Copy link
Contributor

pip install pgvector should fix it

@sambasivaj24
Copy link
Author

thank you, maximeperrindev, I tried the same, still getting the same error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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
Projects
None yet
Development

No branches or pull requests

2 participants