{ "message": "Error : An error occurred: 'str' object does not support item assignment." }

I have a blob storage account where I dropped a single file.
Then I want to add a record on pinecone based on this file using langchain

@app.get("/BlobStorage")
def IndexContainer(storageContainer: str, indexName: str, namespace_name: str):
    logging.info('Python HTTP trigger function IndexContainer processed a request.')    

    try:  
        pinecone.init(
            api_key=os.getenv("pineconeapikey"),
            environment=os.getenv("pineconeenvironment")
        )
         
        connect_str = os.getenv('blobstorageconnectionstring')
        loader = AzureBlobStorageContainerLoader(conn_str=connect_str, container=storageContainer)
        embeddings = OpenAIEmbeddings(deployment=os.getenv("openai_embedding_deployment_name"), 
                                        model=os.getenv("openai_embedding_model_name"),                                   
                                        chunk_size=1)
        
        openai.api_type = "azure"
        openai.api_version =os.getenv("openai_api_version")
        openai.api_base =os.getenv("openai_api_base")
        openai.api_key =os.getenv("openai_api_key")

        documents = loader.load()
        texts = []
        metadatas = []
      
        for doc in documents:
            texts.append(doc.page_content)
            metadatas.append(doc.metadata['source'])

        docsearch = Pinecone.from_texts(
            texts,
            embeddings,
            index_name=indexName,
            metadatas=metadatas,
            namespace=namespace_name
        )
        

        return {
            "message":f"File indexed. This HTTP triggered function executed successfully."
        }
    except Exception as e:
        error_message = f"An error occurred: {str(e)}"
        logging.exception(error_message)
        return {
            "message":f"Error : {error_message}."
        }

I debugged this code line by line and all variables are setup correctly and the exception is only thrown until from_texts method.

However I get this error:

An error occurred: 'str' object does not support item assignment.

What am I missing?

Hi @levalencia

I think you are using the Langchain method here, so maybe their forum would be better to ask. Somewhere in the code a part is trying to .append() something to a ‘str’ object I am guessing. Are you sure this method is the correct method you should use? Be aware, that medatada should be of type [List[dict]] and not just string.

You can check the code here: langchain/langchain/vectorstores/pinecone.py at 57d8a3d1e8fd376d8db8772977870d01ee5e444e · hwchase17/langchain · GitHub

Hope this helps