-
Checked other resources
Commit to Help
Example Codepython ...
from langchain_google_genai import ChatGoogleGenerativeAI
from langchain_google_genai import GoogleGenerativeAIEmbeddings
from langchain_postgres import PGVector
from langchain.chains.question_answering import load_qa_chain
from langchain.prompts import PromptTemplate
from dotenv import find_dotenv, load_dotenv
from langchain_community.embeddings.sentence_transformer import (
SentenceTransformerEmbeddings,
)
import os
load_dotenv(find_dotenv())
def get_env_vars(var: str) -> str:
val = os.getenv(var)
if val is None:
return ValueError(f"Environment variable '{var_name}' not found.")
return val
embeddings = SentenceTransformerEmbeddings(model_name="all-MiniLM-L6-v2")
CONNECTION_STRING = PGVector.connection_string_from_db_params(
driver="psycopg",
host="localhost",
port="5433",
database=get_env_vars("PG_DATABASE"),
user=get_env_vars("PG_USER"),
password=get_env_vars("PG_PASSWORD")
)
pgvector_store = PGVector(
collection_name="testcollection",
connection=CONNECTION_STRING,
embeddings=embeddings,
)
retriever = pgvector_store.as_retriever()
def get_conversational_chain():
prompt_template = """
Answer the question as detailed as possible in markdown from the provided context, make sure to provide all the details, if the answer is not in
provided context just say, "answer is not available in the context", don't provide the wrong answer\n\n
Context:\n {context}?\n
Question: \n{question}\n
Answer:
"""
model = ChatGoogleGenerativeAI(model="gemini-pro",
temperature=0.3)
prompt = PromptTemplate(template = prompt_template, input_variables = ["context", "question"])
chain = load_qa_chain(model, chain_type="stuff", prompt=prompt)
return chain
def user_input(user_question):
docs = retriever.invoke(user_question)
chain = get_conversational_chain()
response = chain(
{"input_documents":docs, "question": user_question}
, return_only_outputs=True)
print(response) DescriptionHave been getting this error for a while but don't know what is wrong, only could find one similar issue but didn't help, please help.
The above exception was the direct cause of the following exception: Traceback (most recent call last): System InfoSystem Information
Package Information
Packages not installed (Not Necessarily a Problem)The following packages were not found:
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
The error you're encountering, To resolve this issue, you should:
If your database schema incorrectly defines an Regarding the By making these adjustments, you should be able to resolve the error and ensure your application correctly interacts with the PostgreSQL database as expected by the LangChain framework.
|
Beta Was this translation helpful? Give feedback.
-
This is occurring due to the mismatch of the created tables from the langchain package. With their new updated version ( |
Beta Was this translation helpful? Give feedback.
This is occurring due to the mismatch of the created tables from the langchain package. With their new updated version (
langchain_postgres
), the application expects an extra 'id' column. What you can do is drop the previously createdlangchain_pg_collection
andlangchain_pg_embedding
tables. Then reinitialize the store which will eventually create the new tables. This approach worked for me.