This guide shows you how to set up and use Pinecone Assistant, a service that allows you to upload documents, ask questions, and receive responses that reference your documents.
You need an API key to make calls to your assistant.Create a new API key in the Pinecone console, or use the widget below to generate a key. If you don’t have a Pinecone account, the widget will sign you up for the free Starter plan.
from pinecone import Pineconepc = Pinecone(api_key="YOUR_API_KEY")assistant = pc.assistant.create_assistant( assistant_name="example-assistant", instructions="Use American English for spelling and grammar.", # Description or directive for the assistant to apply to all responses. region="us", # Region to deploy assistant. Options: "us" (default) or "eu". timeout=30 # Maximum seconds to wait for assistant status to become "Ready" before timing out.)
With Pinecone Assistant, you can upload documents, ask questions, and receive responses that reference your documents. This is known as retrieval-augmented generation (RAG).For this quickstart, download a sample 10-k filing file to your local device.Next, upload the file to your assistant:
Copy
from 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="/path/to/file/Netflix-10-K-01262024.pdf", metadata={"company": "netflix", "document_type": "form 10k"}, timeout=None)
With the sample file uploaded, you can now chat with the assistant. Ask the assistant questions about your document. It returns either a JSON object or a text stream.The following example requests a default response to the message, “Who is the CFO of Netflix?”:
Copy
from pinecone import Pineconefrom pinecone_plugins.assistant.models.chat import Messagepc = Pinecone(api_key='YOUR_API_KEY')assistant = pc.assistant.Assistant(assistant_name="example-assistant")msg = Message(role="user", content="Who is the CFO of Netflix?")resp = assistant.chat(messages=[msg])print(resp)
The example above returns a response like the following:
signed_url provides temporary, read-only access to the relevant file. Anyone with the link can access the file, so treat it as sensitive data. Expires in one hour.