Creates an instance of the Assistant class.
The AssistantOptions for targeting the assistant.
The Pinecone configuration object containing an API key and other configuration parameters needed for API calls.
Readonly_chatReadonly_chatReadonly_chatReadonly_chatReadonly_contextReadonly_deleteReadonly_describeReadonly_listReadonly_uploadSends 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, including contextOptions for controlling multimodal content.
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({ name: 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 ChatCompletionOptions 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({ name: 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 ChatCompletionOptions 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({ name: 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({ name: 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 ContextOptions object containing the query or messages, optional filter, and optional multimodal parameters.
A promise that resolves to a ContextModel object containing the context snippets.
import { Pinecone } from '@pinecone-database/pinecone';
const pc = new Pinecone();
const assistantName = 'test1';
const assistant = pc.assistant({ name: 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({ name: 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.
The ID of the file to describe.
Whether to include the signed URL in the response. Defaults to true.
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({ name: 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.
Optionaloptions: 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({ name: assistantName });
const files = await assistant.listFiles({filter: {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 UploadFileOptions object containing the file path, optional metadata, and optional multimodal flag.
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({ name: 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
Assistantclass 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