Open naveen-vsamy opened 2 weeks ago
When defining "vectorstore" I passed "index" as arg instead of index_name. I changed the code and it worked fine
But still the error was misleading
In your initial code, when you passed a string in index parameter which should actually be pinecone.Index
vectorstore = PineconeVectorStore(embedding = embedding_model, index=index_name)
When you invoke any search function, it calls index.query which is a function from pinecone, but becauuse you passed a String, it tried to call "index" function on a string which is not part of string object. That's why you get the error
'str' object has no attribute 'query'
, which is not an error from lang-chain but it's a Python error.
Here's the source code for reference https://github.com/langchain-ai/langchain/blob/master/libs/partners/pinecone/langchain_pinecone/vectorstores.py#L338
Checked other resources
Example Code
The following code:
Create the connection to Bedrock
bedrock_runtime = boto3.client(service_name='bedrock-runtime', region_name='us-east-1', aws_access_key_id='aws_access_key_id', aws_secret_access_key='aws_secret_access_key' )
os.environ['PINECONE_API_KEY']='pinecone_api_key' index_name = "whale" embedding_model = BedrockEmbeddings(client=bedrock_runtime,model_id="amazon.titan-embed-text-v1" )
vectorstore = PineconeVectorStore(embedding = embedding_model, index=index_name)
similar_search_results = vectorstore.similarity_search(query = "say something...", k = 3)
Raised this following error: AttributeError: 'str' object has no attribute 'query'
Error Message and Stack Trace (if applicable)
embedding_model = BedrockEmbeddings(client=bedrock_runtime,model_id="amazon.titan-embed-text-v1" ) Traceback (most recent call last): File "c:\Users\91822\Documents\Python Scripts\test.py", line 22, in
similar_search_results = vectorstore.similarity_search(query = "say something...", k = 3)
File "C:\Users\91822\AppData\Roaming\Python\Python310\site-packages\langchain_pinecone\vectorstores.py", line 379, in similarity_search
docs_and_scores = self.similarity_search_with_score(
File "C:\Users\91822\AppData\Roaming\Python\Python310\site-packages\langchain_pinecone\vectorstores.py", line 321, in similarity_search_with_score
return self.similarity_search_by_vector_with_score(
File "C:\Users\91822\AppData\Roaming\Python\Python310\site-packages\langchain_pinecone\vectorstores.py", line 338, in similarity_search_by_vector_with_score
results = self._index.query(
AttributeError: 'str' object has no attribute 'query'
Description
I'm trying to do a similarity search on my pinecone vector store through langchain's PineconeVectorStore module. The function is supposed to recieve a string as input arg named "query". But it is throwing the mentioned error.
System Info
System Information
Package Information
Optional packages not installed
Other Dependencies