Im using pinecone for my agent for RAG! but when im using it in Django app im getting this error

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

Hi @innovontek2, and welcome to the Pinecone forums!

Thank you for your question.

Could you share what your vector data looks like prior to upsert? The error you’re getting suggests something is wrong with the format of the data you’re attempting to upsert to Pinecone.

Please have a look at our Quickstart guide and ensure your data format looks similar to the example I’ve linked to. :

index = pc.Index(index_name)

index.upsert(
    vectors=[
        {"id": "vec1", "values": [1.0, 1.5]},
        {"id": "vec2", "values": [2.0, 1.0]},
        {"id": "vec3", "values": [0.1, 3.0]},
    ],
    namespace="ns1"
)

index.upsert(
    vectors=[
        {"id": "vec1", "values": [1.0, -2.5]},
        {"id": "vec2", "values": [3.0, -2.0]},
        {"id": "vec3", "values": [0.5, -1.5]},
    ],
    namespace="ns2"
)

Hope this helps!

Best,
Zack

Hey Zack,
Thanks for your response but i dont think that is the issue here! if run the same code outside my Django application! that is in a separate virtual environment it is working fine, for example i have run the same code like this:

import os
from langchain_pinecone import PineconeVectorStore
from dotenv import load_dotenv
load_dotenv()
from langchain_google_genai import GoogleGenerativeAIEmbeddings
embeddings_model = GoogleGenerativeAIEmbeddings(model="models/embedding-001")
def vector_db(query):
    print("query", query)
    print("type:",type(query))
    query=str(query)
    index_name = "inno-claim-fnol"
    print('Hello')
    vectorstore = PineconeVectorStore(index_name=index_name, embedding=embeddings_model)
    try:
        print("Query payload:", vectorstore._index.query)# Log the payload here
        result = vectorstore.similarity_search(query=query, k=2)
        print("hello2")
        text = ""
        for doc in result:
            text += doc.page_content + "\n"
        print(text)
        return text

    except Exception as e:
        print("Error in vector_db:", e)
        return []
query="what is p&c insurnace?"
result=vector_db(query)
print(result)

here i got the output like this:

query what is p&c insurnace?
type: <class 'str'>
Hello
Query payload: <bound method Index.query of <pinecone.data.index.Index object at 0x0000029390004A70>>
hello2
General Insurance FAQs: 
1. What is P&C insurance? 
A) P&C insurance stands for Property and Casualty insurance. It encompasses 
various policies that protect individuals and businesses from financial losses due 
to unforeseen events like accidents, natural disasters, and theft. 
2. What types of P&C insurance are available? 
A) Common types include auto insurance, homeowners insurance, renters 
insurance, and commercial insurance. Each type covers specific risks and has 
different coverage options. 
3. How do I choose the right insurance policy? 
A) Consider factors like your assets, risk tolerance, budget, and specific needs. 
Consulting an insurance agent can help you compare policies and find the best 
fit. 
4. How can I get a quote for an insurance policy? 
A) You can typically obtain quotes online, by phone, or through an insurance 
agent. Be prepared to provide details about yourself and the assets you want to 
insure. 
5. How can I pay my insurance premiums?
insure. 
5. How can I pay my insurance premiums? 
A) Payment methods vary but often include online payments, automatic bank 
drafts, or mailing checks. 
Claims FAQs: 
6. What should I do if I need to file a claim? 
A) Contact your insurance company as soon as possible. They will guide you 
through the process and provide the necessary forms. 
7. What information do I need to provide when filing a claim? 
A) Be prepared to provide your policy number, name, contact information, loss 
type, date and time of the incident, description of the damages, and supporting 
documentation (police reports, photos, etc.). 
8. What documents do I need to submit to claim my policy? 
A) Commonly required documents include:

General Insurance FAQs: 
1. What is P&C insurance? 
A) P&C insurance stands for Property and Casualty insurance. It encompasses 
various policies that protect individuals and businesses from financial losses due 
to unforeseen events like accidents, natural disasters, and theft. 
2. What types of P&C insurance are available? 
A) Common types include auto insurance, homeowners insurance, renters 
insurance, and commercial insurance. Each type covers specific risks and has 
different coverage options. 
3. How do I choose the right insurance policy? 
A) Consider factors like your assets, risk tolerance, budget, and specific needs. 
Consulting an insurance agent can help you compare policies and find the best 
fit. 
4. How can I get a quote for an insurance policy? 
A) You can typically obtain quotes online, by phone, or through an insurance 
agent. Be prepared to provide details about yourself and the assets you want to 
insure. 
5. How can I pay my insurance premiums?
insure. 
5. How can I pay my insurance premiums? 
A) Payment methods vary but often include online payments, automatic bank 
drafts, or mailing checks. 
Claims FAQs: 
6. What should I do if I need to file a claim? 
A) Contact your insurance company as soon as possible. They will guide you 
through the process and provide the necessary forms. 
7. What information do I need to provide when filing a claim? 
A) Be prepared to provide your policy number, name, contact information, loss 
type, date and time of the incident, description of the damages, and supporting 
documentation (police reports, photos, etc.). 
8. What documents do I need to submit to claim my policy? 
A) Commonly required documents include:

But the problem is only occurring if im adding this code in my Django project:

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(query, k=2)
    print("result",result)
    text = ""
    for doc in result:
        text += doc.page_content + "\n"
    print(text)
    return text

The same code as above but here when i run the application and the query from frontend im getting this error!

verify_history : [{'user': 'what is p&c insurnace'}]
refined_query : What is Property and Casualty (P&C) insurance defined as?
query What is Property and Casualty (P&C) insurance defined as?
type: <class 'str'>
vectorstore <langchain_pinecone.vectorstores.PineconeVectorStore object at 0x000002CB9CD5DF70>
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 174, in AI_CHAT_AGENT
    context = vector_db(refined_query)
              ^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\Main_Project\pythonProject\Back_end\Innovontech\AI\utils.py", line 282, in vector_db
    result = vectorstore.similarity_search(query, 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
[30/May/2024 12:11:19] "POST /AI/AI_CHAT_AGENT/ HTTP/1.1" 500 222069

Can you please help me with this issue! if you want any more information to tackle this issue let me know