This feature is in public beta and is not recommended for production usage. Join the beta waitlist and review the preview terms for more details.

This page shows you how to chat with a Pinecone Assistant.

Install the Pinecone Assistant Python plugin

To use the chat completion endpoint for the Pinecone Assistant with the Python client, upgrade the client and install the pinecone-plugin-assistant package as follows:

To learn about the concepts related to Pinecone Assistant, see Understanding Knowledge Assistant.

Chat with an assistant with the Assistant API

To chat with an assistant, use the chat completion assistant endpoint. This operation returns either a JSON object or a text stream.

The content parameter in the request must not be empty.

Request a JSON response

The following example requests a JSON response to the message, “What is the maximum height of a red pine?“:

The example above returns a result like the following:

{"chat_completion":
  {
    "id":"chatcmpl-9OtJCcR0SJQdgbCDc9JfRZy8g7VJR",
    "choices":[
      {
        "finish_reason":"stop",
        "index":0,
        "message":{
          "role":"assistant",
          "content":"The maximum height of a red pine (Pinus resinosa) is up to 25 meters."
        }
      }
    ],
    "model":"gpt-4-turbo-2024-04-09"},
    "context":{
      "results":[
        {
          "id":"b3639f36-327f-4f55-a43e-53838097b18e.txt",
          "source":"b3639f36-327f-4f55-a43e-53838097b18e.txt",
          "text":"Page 1",
          "score":0.0011116682,
          "path":[
            "d4439710-ca5d-4f19-8078-ccd261a1c466"
          ]
        }, 
        {
          "id":"6837ef7a-37c8-44d5-abff-c377a460aba3.txt",
          "source":"6837ef7a-37c8-44d5-abff-c377a460aba3.txt",
          "text":"Page 1","score":0.0011116682, 
          "path":["525b93c5-7c07-4114-ba59-f83ab8aba95c"]
        }
      ]
    }
  }

The response contains an object called choices which contains a message object. The value of role in this object is assistant, indicating that this is a response from the assistant.

The message has a content value of “The maximum height of a red pine (Pinus resinosa) is up to 25 meters.” This value represents the response from the assistant to the message in the request.

Request a streaming response

The following example requests a text streaming response to the message, “What is the maximum height of a red pine?“:

The example above returns a result like the following:

{"chat_completion":
  {
    "id":"chatcmpl-9OtJCcR0SJQdgbCDc9JfRZy8g7VJR",
    "choices":[
      {
        "finish_reason":"stop",
        "index":0,
        "delta":{
          "role":"",
          "content":"The"
        }
      }
    ],
    "model":"gpt-4-turbo-2024-04-09"}
  }

Provide conversation history in a chat request

Models lack memory of previous requests, so any relevant messages from earlier in the conversation must be present in the messages object.

In the following example, the messages object includes prior messages that are necessary for interpreting the newest message.

The above example request returns a response like the following:

{"chat_completion":
  {
    "id":"chatcmpl-9OtJCcR0SJQdgbCDc9JfRZy8g7VJR",
    "choices":[
      {
        "finish_reason":"stop",
        "index":0,
        "message":{
          "role":"assistant",
          "content":"The maximum diameter of a red pine (Pinus resinosa) is 75 centimeters [1, pp. 1]"
        }
      }
    ],
    "model":"gpt-4-turbo-2024-04-09"},
    "context":{
      "results":[
        {
          "id":"b3639f36-327f-4f55-a43e-53838097b18e.txt",
          "source":"b3639f36-327f-4f55-a43e-53838097b18e.txt",
          "text":"Page 1",
          "score":0.0011116682,
          "path":[
            "d4439710-ca5d-4f19-8078-ccd261a1c466"
          ]
        }, 
        {
          "id":"6837ef7a-37c8-44d5-abff-c377a460aba3.txt",
          "source":"6837ef7a-37c8-44d5-abff-c377a460aba3.txt",
          "text":"Page 1","score":0.0011116682, 
          "path":["525b93c5-7c07-4114-ba59-f83ab8aba95c"]
        }
      ]
    }
  }

Retrieve chat message from response object

The response object from the Assistant API contains the assistant’s chat response along with other information. The message string is contained in the following JSON object:

choices.[0].message.content

The following example extracts the response message from the assistant and prints it to the console:

The example creates output like the following:

A red pine, scientifically known as *Pinus resinosa*, is a medium-sized tree that can grow up to 25 meters high and 75 centimeters in diameter. [1, pp. 1]

Chat with an assistant in the Pinecone Console

To chat with an assistant in the Pinecone Console, follow these steps:

  1. Open the Pinecone console.
  2. Select your project.
  3. Select Assistant (Beta) in the left panel.
  4. Select your assistant.
  5. Select the Chats tab.
  6. Enter a prompt in the text field.
  7. Click the arrow icon.

The response to your prompt appears in the Chat tab. References to imported files appear as hyperlinks to the source file.