Pinecone TypeScript SDK - v9.0.0
    Preparing search index...

    Class Assistant

    An assistant answers questions using the files you provide.

    Access it through Pinecone.assistant; do not construct it directly. Use Assistants through pc.assistants to create and manage assistants.

    import { Pinecone } from '@pinecone-database/pinecone';
    const pc = new Pinecone();
    const assistant = pc.assistant({ name: 'support-guide' });
    Index
    assistantName: string

    The name of the assistant targeted by this client.

    • Generates an answer from the assistant with structured citations.

      Server errors are retried according to PineconeConfiguration.maxRetries.

      Parameters

      • options: ChatOptions

        Messages and optional model, file filter, and response settings.

      Returns Promise<ChatModel>

      The answer in message, with citations and token usage.

      Errors.PineconeArgumentError if the messages or model fail validation.

      import { Pinecone } from '@pinecone-database/pinecone';
      const pc = new Pinecone();
      const assistant = pc.assistant({ name: 'support-guide' });
      const response = await assistant.chat({
      messages: [{ role: 'user', content: 'How do I return an order?' }],
      });
      console.log(response.message, response.citations);

      Assistant.chatStream for streamed answers; Assistant.chatCompletion for completion-style responses.

    • Generates an assistant answer in a chat completion response format.

      Server errors are retried according to PineconeConfiguration.maxRetries.

      Parameters

      Returns Promise<ChatCompletionModel>

      Response choices containing the answer, with model and token usage.

      Errors.PineconeArgumentError if the messages or model fail validation.

      import { Pinecone } from '@pinecone-database/pinecone';
      const pc = new Pinecone();
      const assistant = pc.assistant({ name: 'support-guide' });
      const response = await assistant.chatCompletion({
      messages: [{ role: 'user', content: 'How do I return an order?' }],
      });
      console.log(response.choices);

      Assistant.chat for structured citations and additional response options.

    • Streams an assistant answer and its structured citations.

      Requires a Node.js runtime. Server errors are retried according to PineconeConfiguration.maxRetries before streaming begins.

      Parameters

      • options: ChatOptions

        Messages and optional model, file filter, and context settings.

      Returns Promise<ChatStream<StreamedChatResponse>>

      An async iterable of message, content, citation, and completion chunks.

      Errors.PineconeArgumentError if the messages or model fail validation.

      import { Pinecone } from '@pinecone-database/pinecone';
      const pc = new Pinecone();
      const assistant = pc.assistant({ name: 'support-guide' });
      const stream = await assistant.chatStream({
      messages: [{ role: 'user', content: 'How do I return an order?' }],
      });
      for await (const chunk of stream) {
      if (chunk.type === 'content_chunk') console.log(chunk.delta.content);
      }

      Assistant.chat for a complete answer; Assistant.chatCompletionStream for completion-style chunks.

    • Retrieves relevant context snippets without generating an answer.

      Parameters

      • options: ContextOptions

        A query or conversation messages, with optional file filter and snippet settings.

      Returns Promise<ContextModel>

      Relevant snippets with source references and usage information.

      Errors.PineconeArgumentError if neither query nor messages is supplied.

      import { Pinecone } from '@pinecone-database/pinecone';
      const pc = new Pinecone();
      const assistant = pc.assistant({ name: 'support-guide' });
      const response = await assistant.context({ query: 'How do I return an order?' });
      console.log(response.snippets);

      Assistant.chat to generate an answer from the context.

    • Deletes a file from the assistant asynchronously.

      Parameters

      • fileId: string

        The ID of the file to delete.

      Returns Promise<OperationModel>

      An operation to track deletion with Assistant.describeOperation.

      Errors.PineconeArgumentError if fileId is empty.

      import { Pinecone } from '@pinecone-database/pinecone';
      const pc = new Pinecone();
      const assistant = pc.assistant({ name: 'support-guide' });
      const operation = await assistant.deleteFile('1a56ddd0-c6d8-4295-80c0-9bfd6f5cb87b');
      console.log(operation.id);
    • Gets file details and processing status.

      Parameters

      • fileId: string

        The file ID returned by an upload operation or file listing.

      • includeUrl: boolean = true

        Include a signed download URL; defaults to true.

      Returns Promise<AssistantFileModel>

      File details, including status and a download URL when requested.

      Errors.PineconeArgumentError if fileId is empty.

      import { Pinecone } from '@pinecone-database/pinecone';
      const pc = new Pinecone();
      const assistant = pc.assistant({ name: 'support-guide' });
      const file = await assistant.describeFile('1a56ddd0-c6d8-4295-80c0-9bfd6f5cb87b');
      console.log(file.status);

      Assistant.listFiles to find file IDs.

    • Gets the current status of an asynchronous file operation.

      Call again to check progress; this call does not wait for completion.

      Parameters

      • operationId: string

        The operation ID returned by a file upload, upsert, deletion, or operation listing.

      Returns Promise<OperationModel>

      Operation details including status and any error.

      Errors.PineconeArgumentError if operationId is empty.

      import { Pinecone } from '@pinecone-database/pinecone';
      const pc = new Pinecone();
      const assistant = pc.assistant({ name: 'support-guide' });
      const operation = await assistant.uploadFile({ path: 'returns-policy.pdf' });
      const result = await assistant.describeOperation(operation.id);
      console.log(result.status);

      Assistant.listOperations to find operations.

    • Lists files uploaded to the assistant.

      Parameters

      • Optionaloptions: ListFilesOptions

        Optional file metadata filter; omit to list files without filtering.

      Returns Promise<AssistantFilesList>

      File details in files, including processing status.

      import { Pinecone } from '@pinecone-database/pinecone';
      const pc = new Pinecone();
      const assistant = pc.assistant({ name: 'support-guide' });
      const result = await assistant.listFiles({
      filter: { category: { $eq: 'returns' } },
      });
      console.log(result.files);

      Assistant.describeFile for details of one file.

    • Lists one page of asynchronous operations on the assistant.

      Parameters

      Returns Promise<OperationList>

      Operations and pagination information; pass pagination.next as paginationToken for the next page.

      import { Pinecone } from '@pinecone-database/pinecone';
      const pc = new Pinecone();
      const assistant = pc.assistant({ name: 'support-guide' });
      const page = await assistant.listOperations({ status: 'Processing' });
      console.log(page.operations);
      if (page.pagination?.next) {
      const nextPage = await assistant.listOperations({
      status: 'Processing',
      paginationToken: page.pagination.next,
      });
      console.log(nextPage.operations);
      }

      Assistant.describeOperation for the status of one operation.

    • Uploads a new file for the assistant to use.

      Processing continues asynchronously; check the returned operation with Assistant.describeOperation. Stream inputs are sent in a single attempt.

      Parameters

      • options: UploadFileOptions

        A local path, or file plus fileName, with optional metadata and multimodal processing.

      Returns Promise<OperationModel>

      An operation whose id tracks processing and whose fileId identifies the file.

      Errors.PineconeArgumentError if file input or its required filename is missing.

      import { Pinecone } from '@pinecone-database/pinecone';
      const pc = new Pinecone();
      const assistant = pc.assistant({ name: 'support-guide' });
      const operation = await assistant.uploadFile({
      path: 'returns-policy.pdf',
      metadata: { category: 'returns' },
      });
      console.log(operation.id);

      Assistant.upsertFile to create or replace a file at an ID you supply.

    • Creates or replaces a file at an ID you supply.

      Processing continues asynchronously; check the returned operation with Assistant.describeOperation. Stream inputs are sent in a single attempt.

      Parameters

      • options: UpsertFileOptions

        The assistantFileId and a local path, or file plus fileName, with optional multimodal processing.

      Returns Promise<OperationModel>

      An operation whose id tracks processing and whose fileId identifies the file.

      Errors.PineconeArgumentError if the file ID, file input, or required filename is missing.

      import { Pinecone } from '@pinecone-database/pinecone';
      const pc = new Pinecone();
      const assistant = pc.assistant({ name: 'support-guide' });
      const operation = await assistant.upsertFile({
      assistantFileId: '1a56ddd0-c6d8-4295-80c0-9bfd6f5cb87b',
      path: 'returns-policy.pdf',
      });
      console.log(operation.id);

      Assistant.uploadFile to create a file with an assigned ID and optional metadata.