Skip to main content
Pinecone Docs

Search documentation

Type to search this documentation.

On this pageOverview

Upload file to assistant

For guidance and examples, see Manage files.

Python
# To use the Python SDK, install the plugin:
# pip install --upgrade pinecone pinecone-plugin-assistant

from pinecone import Pinecone
pc = Pinecone(api_key="YOUR_API_KEY")

# Get the assistant.
assistant = pc.assistant.Assistant(
    assistant_name="example-assistant", 
)

# Upload a file from a local path.
response = assistant.upload_file(
    file_path="/Users/jdoe/Downloads/example_file.txt",
    metadata={"published": "2024-01-01", "document_type": "manuscript"},
    timeout=None
)

# Upload from an in-memory binary stream.
from io import BytesIO

# Create a BytesIO stream with some content.
md_text = "# Title\n\ntext"
stream = BytesIO(md_text.encode("utf-8"))

# Upload the stream.
response_bytes_stream = assistant.upload_bytes_stream(
    stream=stream,
    file_name="example_file.md",
    timeout=None
)
JavaScript
import { Pinecone } from '@pinecone-database/pinecone'

const pc = new Pinecone({ apiKey: 'YOUR_API_KEY' });

const assistantName = 'example-assistant';
const assistant = pc.Assistant(assistantName);
await assistant.uploadFile({
  path: '/Users/jdoe/Downloads/example_file.txt',
  metadata: { 'published': '2024-01-01', 'document_type': 'manuscript' },
});
curl
PINECONE_API_KEY="YOUR_API_KEY"
ASSISTANT_NAME="example-assistant"
ENCODED_METADATA="%7B%22published%22%3A%222024-01-01%22%2C%22document_type%22%3A%22script%22%7D" # URL encoded metadata - See w3schools.com/tags/ref_urlencode.ASP
LOCAL_FILE_PATH="/Users/jdoe/Downloads/example_file.txt"

curl -X POST "https://prod-1-data.ke.pinecone.io/assistant/files/$ASSISTANT_NAME?metadata=$ENCODED_METADATA" \
     -H "Api-Key: $PINECONE_API_KEY" \
     -F "file=@$LOCAL_FILE_PATH"
curl
{
  "name": "example-file.txt",
  "id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
  "metadata": "{ 'published': '2024-01-01', 'document_type': 'manuscript' }",
  "created_on": "2023-11-07T05:31:56Z",
  "updated_on": "2023-11-07T05:31:56Z",
  "status": "Processing",
  "percent_done": 50,
  "signed_url": "https://storage.googleapis.com/bucket/file.pdf",
  "error_message": "<string>"
}

POST /files/{assistant_name}

  • assistant_name (path, string, required) — The name of the assistant to upload files to.
  • metadata (query, string) — Optional JSON-encoded metadata for files.
  • 200 — File upload has been accepted.
  • 400 — Bad request. The request body included invalid request parameters.
  • 401 — Unauthorized. Possible causes: Invalid API key.
  • 404 — Assistant not found.
  • 500 — Internal server error.
Suggest an edit

Propose a replacement for this page. The site team reviews it before applying any changes.

Export
Documentation menu