This is my code:
from langchain_pinecone import PineconeVectorStore
from dotenv import load_dotenv
load_dotenv()
google_gemini=ChatGoogleGenerativeAI(model="gemini-pro",temperature=0.3)
def vector_db(query):
print("query", query)
print("type:",type(query))
query=str(query)
index_name = "inno-claim-fnol"
vectorstore = PineconeVectorStore(index_name=index_name, embedding=embeddings_model)
print("vectorstore",vectorstore)
print("Query payload:", vectorstore._index.query) # Log the payload here
result = vectorstore.similarity_search("what is p&c insurance?", k=2)
print("result",result)
text = ""
for doc in result:
text += doc.page_content + "\n"
print(text)
return text
For this im getting this error:
query What is Property and Casualty (P&C) insurance defined as?
type: <class 'str'>
vectorstore <langchain_pinecone.vectorstores.PineconeVectorStore object at 0x0000020FDFA65910>
Query payload: <bound method Index.query of <pinecone.data.index.Index object at 0x0000020FDFE57DD0>>
Internal Server Error: /AI/AI_CHAT_AGENT/
Traceback (most recent call last):
File "D:\Main_Project\.venv\Lib\site-packages\django\core\handlers\exception.py", line 55, in inner
response = get_response(request)
^^^^^^^^^^^^^^^^^^^^^
File "D:\Main_Project\.venv\Lib\site-packages\django\core\handlers\base.py", line 197, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Main_Project\.venv\Lib\site-packages\django\views\decorators\csrf.py", line 65, in _view_wrapper
return view_func(request, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Main_Project\.venv\Lib\site-packages\django\views\generic\base.py", line 104, in view
return self.dispatch(request, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Main_Project\.venv\Lib\site-packages\rest_framework\views.py", line 509, in dispatch
response = self.handle_exception(exc)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Main_Project\.venv\Lib\site-packages\rest_framework\views.py", line 469, in handle_exception
self.raise_uncaught_exception(exc)
File "D:\Main_Project\.venv\Lib\site-packages\rest_framework\views.py", line 480, in raise_uncaught_exception
raise exc
File "D:\Main_Project\.venv\Lib\site-packages\rest_framework\views.py", line 506, in dispatch
response = handler(request, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Main_Project\.venv\Lib\site-packages\rest_framework\decorators.py", line 50, in handler
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "D:\Main_Project\pythonProject\Back_end\Innovontech\AI\views.py", line 172, in AI_CHAT_AGENT
context = vector_db(refined_query)
^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Main_Project\pythonProject\Back_end\Innovontech\AI\utils.py", line 278, in vector_db
result = vectorstore.similarity_search("what is p&c insurance?", k=2)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Main_Project\.venv\Lib\site-packages\langchain_pinecone\vectorstores.py", line 247, in similarity_search
docs_and_scores = self.similarity_search_with_score(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Main_Project\.venv\Lib\site-packages\langchain_pinecone\vectorstores.py", line 192, in similarity_search_with_score
return self.similarity_search_by_vector_with_score(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Main_Project\.venv\Lib\site-packages\langchain_pinecone\vectorstores.py", line 209, in similarity_search_by_vector_with_score
results = self._index.query(
^^^^^^^^^^^^^^^^^^
File "D:\Main_Project\.venv\Lib\site-packages\pinecone\utils\error_handling.py", line 10, in inner_func
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "D:\Main_Project\.venv\Lib\site-packages\pinecone\data\index.py", line 399, in query
response = self._vector_api.query(
^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Main_Project\.venv\Lib\site-packages\pinecone\core\client\api_client.py", line 772, in __call__
return self.callable(self, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Main_Project\.venv\Lib\site-packages\pinecone\core\client\api\data_plane_api.py", line 844, in __query
return self.call_with_http_info(**kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Main_Project\.venv\Lib\site-packages\pinecone\core\client\api_client.py", line 834, in call_with_http_info
return self.api_client.call_api(
^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Main_Project\.venv\Lib\site-packages\pinecone\core\client\api_client.py", line 409, in call_api
return self.__call_api(resource_path, method,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Main_Project\.venv\Lib\site-packages\pinecone\core\client\api_client.py", line 181, in __call_api
body = self.sanitize_for_serialization(body)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Main_Project\.venv\Lib\site-packages\pinecone\core\client\api_client.py", line 274, in sanitize_for_serialization
key: cls.sanitize_for_serialization(val) for key, val in model_to_dict(obj, serialize=True).items()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Main_Project\.venv\Lib\site-packages\pinecone\core\client\api_client.py", line 288, in sanitize_for_serialization
raise PineconeApiValueError('Unable to prepare type {} for serialization'.format(obj.__class__.__name__))
pinecone.core.client.exceptions.PineconeApiValueError: Unable to prepare type Repeated for serialization
[29/May/2024 14:01:58] "POST /AI/AI_CHAT_AGENT/ HTTP/1.1" 500 221800