Creates an instance of the Assistant
class.
The name of the assistant.
The Pinecone configuration object containing an API key and other configuration parameters needed for API calls.
An error if no assistant name is provided.
Readonly
_chatReadonly
_chatReadonly
_chatReadonly
_chatReadonly
_contextReadonly
_deleteReadonly
_describeReadonly
_listReadonly
_uploadPrivate
configSends a message to the assistant and receives a response. Retries the request if the server fails.
A ChatOptions object containing the message and optional parameters to send to the assistant.
A promise that resolves to a ChatModel object containing the response from the assistant.
import { Pinecone } from '@pinecone-database/pinecone';
const pc = new Pinecone();
const assistantName = 'test1';
const assistant = pc.assistant(assistantName);
const chatResp = await assistant.chat({messages: [{role: 'user', content: "What is the capital of France?"}]});
// {
// id: '000000000000000023e7fb015be9d0ad',
// finishReason: 'stop',
// message: {
// role: 'assistant',
// content: 'The capital of France is Paris.'
// },
// model: 'gpt-4o-2024-05-13',
// citations: [ { position: 209, references: [Array] } ],
// usage: { promptTokens: 493, completionTokens: 38, totalTokens: 531 }
// }
Sends a message to the assistant and receives a response that is compatible with [OpenAI's Chat Completion API](https://platform.openai.com/docs/guides/text-generation. Retries the request if the server fails.
A ChatOptions object containing the message and optional parameters to send to an assistant.
A promise that resolves to a ChatCompletionModel object containing the response from the assistant.
import { Pinecone } from '@pinecone-database/pinecone';
const pc = new Pinecone();
const assistantName = 'test1';
const assistant = pc.assistant(assistantName);
const chatCompletion = await assistant.chatCompletion({ messages: [{ role: 'user', content: 'What is the capital of France?' }]});
console.log(chatCompletion);
// {
// id: "response_id",
// choices: [
// {
// finishReason: "stop",
// index: 0,
// message: {
// role: "assistant",
// content: "The data mentioned is described as \"some temporary data\" [1].\n\nReferences:\n1. [test-chat.txt](https://storage.googleapis.com/knowledge-prod-files/your_file_resource) \n"
// }
// }
// ],
// model: "gpt-4o-2024-05-13",
// usage: {
// promptTokens: 371,
// completionTokens: 19,
// totalTokens: 390
// }
// }
Sends a message to the assistant and receives a streamed response as ChatStream
A ChatOptions object containing the message and optional parameters to send to an assistant.
A promise that resolves to a ChatStream
import { Pinecone } from '@pinecone-database/pinecone';
const pc = new Pinecone();
const assistantName = 'test1';
const assistant = pc.assistant(assistantName);
const chatStream = await assistant.chatCompletionStream({messages: [{role: 'user', content: "What is the capital of France?"}]});
// stream the response and log each chunk
for await (const chunk of newStream) {
if (chunk.choices.length > 0 && chunk.choices[0].delta.content) {
process.stdout.write(chunk.choices[0].delta.content);
}
}
// { id: 'response_id', choices: [{ index: 0, delta: { role: 'assistant' }, finishReason: null }], model: 'gpt-4o-2024-05-13', usage: null }
// { id: 'response_id', choices: [{ index: 0, delta: { content: 'The' }}, finishReason: null }], model: 'gpt-4o-2024-05-13', usage: null }
// { id: 'response_id', choices: [{ index: 0, delta: { content: ' test' }}, finishReason: null }], model: 'gpt-4o-2024-05-13', usage: null }
// { id: 'response_id', choices: [], model: 'gpt-4o-2024-05-13', usage: { promptTokens: 371, completionTokens: 48, totalTokens: 419 }}
Sends a message to the assistant and receives a streamed response as ChatStream
A ChatOptions object containing the message and optional parameters to send to the assistant.
A promise that resolves to a ChatStream
import { Pinecone } from '@pinecone-database/pinecone';
const pc = new Pinecone();
const assistantName = 'test1';
const assistant = pc.assistant(assistantName);
const chatStream = await assistant.chatStream({ messages: [{ role: 'user', content: 'What is the capital of France?'}]});
// stream the response and log each chunk
for await (const chunk of newStream) {
console.log(chunk);
}
// each chunk will have a variable shape depending on the type:
// { type:"message_start", id:"response_id", model:"gpt-4o-2024-05-13", role:"assistant"}
// { type:"content_chunk", id:"response_id", model:"gpt-4o-2024-05-13", delta:{ content:"The"}}
// { type:"content_chunk", id:"response_id", model:"gpt-4o-2024-05-13", delta:{ content:" test"}}
// { type:"message_end", id:"response_id", model:"gpt-4o-2024-05-13", finishReason:"stop",usage:{ promptTokens:371,completionTokens:48,totalTokens:419}}
Retrieves the context snippets used by an assistant during the retrieval process.
A promise that resolves to a Context object containing the context snippets.
import { Pinecone } from '@pinecone-database/pinecone';
const pc = new Pinecone();
const assistantName = 'test1';
const assistant = pc.assistant(assistantName);
const response = await assistant.context({query: "What is the capital of France?"});
console.log(response);
// {
// snippets: [
// {
// type: 'text',
// content: 'The capital of France is Paris.',
// score: 0.9978925,
// reference: [Object]
// },
// ],
// usage: { promptTokens: 527, completionTokens: 0, totalTokens: 527 }
// }
Deletes a file uploaded to an assistant by ID.
A promise that resolves to void on success.
import { Pinecone } from '@pinecone-database/pinecone';
const pc = new Pinecone();
const assistantName = 'test1';
const assistant = pc.assistant(assistantName);
const files = await assistant.listFiles();
let fileId: string;
if (files.files) {
fileId = files.files[0].id;
await assistant.deleteFile({fileId: fileId});
}
Describes a file uploaded to an assistant.
A promise that resolves to a AssistantFileModel object containing the file details.
import { Pinecone } from '@pinecone-database/pinecone';
const pc = new Pinecone();
const assistantName = 'test1';
const assistant = pc.assistant(assistantName);
const files = await assistant.listFiles();
let fileId: string;
if (files.files) {
fileId = files.files[0].id;
} else {
fileId = '';
}
const resp = await assistant.describeFile({fileId: fileId})
console.log(resp);
// {
// name: 'test-file.txt',
// id: '1a56ddd0-c6d8-4295-80c0-9bfd6f5cb87b',
// metadata: undefined,
// createdOn: 2025-01-06T19:14:21.969Z,
// updatedOn: 2025-01-06T19:14:36.925Z,
// status: 'Available',
// percentDone: 1,
// signedUrl: undefined,
// errorMessage: undefined
// }
Lists files (with optional filter) uploaded to an assistant.
Optional
options: ListFilesOptionsA ListFilesOptions object containing optional parameters to filter the list of files.
A promise that resolves to a AssistantFilesList object containing a list of files.
import { Pinecone } from '@pinecone-database/pinecone';
const pc = new Pinecone();
const assistantName = 'test1';
const assistant = pc.assistant(assistantName);
const files = await assistant.listFiles({filter: {metadata: {key: 'value'}}});
console.log(files);
// {
// files: [
// {
// name: 'temp-file.txt',
// id: '1a56ddd0-c6d8-4295-80c0-9bfd6f5cb87b',
// metadata: undefined,
// createdOn: 2025-01-06T19:14:21.969Z,
// updatedOn: 2025-01-06T19:14:36.925Z,
// status: 'Available',
// percentDone: 1,
// signedUrl: undefined,
// errorMessage: undefined
// }
// ]
// }
Uploads a file to an assistant.
Note: This method does not use the generated code from the OpenAPI spec.
A UploadFile object containing the file path and optional metadata.
A promise that resolves to a AssistantFileModel object containing the file details.
import { Pinecone } from '@pinecone-database/pinecone';
const pc = new Pinecone();
const assistantName = 'test1';
const assistant = pc.assistant(assistantName);
await assistant.uploadFile({path: "test-file.txt", metadata: {"test-key": "test-value"}})
// {
// name: 'test-file.txt',
// id: '921ad74c-2421-413a-8c86-fca81ceabc5c',
// metadata: { 'test-key': 'test-value' },
// createdOn: Invalid Date, // Note: these dates resolve in seconds
// updatedOn: Invalid Date,
// status: 'Processing',
// percentDone: null,
// signedUrl: null,
// errorMessage: null
// }
The
Assistant
class holds the data plane methods for interacting with Assistants.This class can be instantiated through a Pinecone object, and is used to interact with a specific assistant.
Example