# To use the Python SDK, install the plugin:# pip install --upgrade pinecone pinecone-plugin-assistantfrom pinecone import Pineconepc = Pinecone(api_key="YOUR_API_KEY")# Get an assistant.assistant = pc.assistant.Assistant( assistant_name="example-assistant", )# Upload a file.response = assistant.upload_file( file_path="/Users/jdoe/Downloads/example_file.txt", timeout=None)
It may take several minutes for your assistant to process your file. You can check the status of your file to determine if it is ready to use.
You can upload a file to an assistant using the Pinecone console. Select the assistant you want to upload to and add the file in the Assistant playground.
You can upload a file with metadata. Metadata is a dictionary of key-value pairs that you can use to store additional information about the file. For example, you can use metadata to store the file’s name, document type, publish date, or any other relevant information.
Copy
# To use the Python SDK, install the plugin:# pip install --upgrade pinecone pinecone-plugin-assistantfrom pinecone import Pineconepc = Pinecone(api_key="YOUR_API_KEY")# Get the assistant.assistant = pc.assistant.Assistant( assistant_name="example-assistant", )# Upload a file.response = assistant.upload_file( file_path="/Users/jdoe/Downloads/example_file.txt", metadata={"published": "2024-01-01", "document_type": "manuscript"}, timeout=None)
You can upload a file directly from an in-memory binary stream using the Python SDK and the BytesIO class.
When uploading text-based files (like .txt, .md, .json, etc.) through BytesIO streams, make sure the content is encoded in UTF-8 format.
Python
Copy
from pinecone import Pineconefrom io import BytesIOpc = Pinecone(api_key="YOUR_API_KEY")# Get an assistantassistant = pc.assistant.Assistant( assistant_name="example-assistant", )# Create a BytesIO stream with some contentmd_text = "# Title\n\ntext"# Note: Assistant currently supports only utf-8 for text-based filesstream = BytesIO(md_text.encode("utf-8"))# Upload the streamresponse = assistant.upload_bytes_stream( stream=stream, file_name="example_file.md", timeout=None)