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

    Class Documents

    Read and write documents whose fields follow a schema-based index's schema. Access through Index.documents; do not construct this client directly. Unlike vector operations on Index, these operations work with document fields and scoring methods.

    import { Pinecone } from '@pinecone-database/pinecone';
    const pc = new Pinecone();
    const index = pc.index({ name: 'product-documents', namespace: 'products-en' });
    const result = await index.documents.fetch({ ids: ['trail-shoe-42'] });
    console.log(result.documents);
    Index
    • Delete schema-based documents by IDs, filter, or an entire namespace.

      deleteAll: true removes all documents in this client's namespace.

      Parameters

      Returns Promise<DeleteDocumentsResponse>

      The number of documents matched by the request in matchedRecords.

      Errors.PineconeArgumentError when the selection is missing or invalid.

      import { Pinecone } from '@pinecone-database/pinecone';
      const pc = new Pinecone();
      const index = pc.index({ name: 'product-documents', namespace: 'products-en' });

      const result = await index.documents.delete({ ids: ['trail-shoe-42'] });
      console.log(result.matchedRecords);

      Index.deleteMany for vector records.

    • Fetch schema-based documents by IDs or a metadata filter.

      Fetching by filter returns one page at a time.

      Parameters

      Returns Promise<FetchDocumentsResponse>

      Documents keyed by ID in documents, the namespace, usage, and a continuation token when available.

      Errors.PineconeArgumentError when the selection is missing or invalid, or pagination is requested without a filter.

      import { Pinecone } from '@pinecone-database/pinecone';
      const pc = new Pinecone();
      const index = pc.index({ name: 'product-documents', namespace: 'products-en' });

      const result = await index.documents.fetch({ ids: ['trail-shoe-42'] });
      console.log(result.documents['trail-shoe-42']);

      Documents.list to list document IDs; Index.fetch for vector records.

    • Search schema-based documents using one or more scoring methods.

      Choose scoring fields and methods supported by your index schema.

      Parameters

      • options: SearchDocumentsOptions

        Scoring methods in scoreBy, the result count topK, and optional filters and returned fields.

      Returns Promise<SearchDocumentsResponse>

      Ranked matches, the namespace, and usage information.

      Errors.PineconeArgumentError when scoreBy is missing or empty, or topK is missing or less than 1.

      import { Pinecone } from '@pinecone-database/pinecone';
      const pc = new Pinecone();
      const index = pc.index({ name: 'product-documents', namespace: 'products-en' });

      const result = await index.documents.search({
      scoreBy: [{ type: 'text', fields: ['title'], query: 'hiking shoes' }],
      topK: 5, includeFields: ['title'],
      });
      console.log(result.matches);

      Index.searchRecords for integrated embedding search; Index.query for vector similarity queries.

    • Partially update schema-based documents selected by IDs or a filter.

      Unspecified fields are preserved. The example changes category while retaining the document's title and other fields.

      Parameters

      • options: UpdateDocumentsOptions

        Per-ID changes in documents, or a filter with non-empty setFields and/or removeFields.

      Returns Promise<UpdateDocumentsResponse>

      The number of documents matched by the request in matchedRecords.

      Errors.PineconeArgumentError when the selection or field changes are missing or incompatible.

      import { Pinecone } from '@pinecone-database/pinecone';
      const pc = new Pinecone();
      const index = pc.index({ name: 'product-documents', namespace: 'products-en' });

      await index.documents.update({
      documents: [{ _id: 'trail-shoe-42', category: 'hiking-footwear' }],
      });

      Documents.upsert to write documents; Index.update for vector records.