cloudflare-vectorize
    Preparing search index...

    Class Vectorize

    Provides a TypeScript client for interacting with the Cloudflare Vectorize API.

    The Vectorize class enables management and querying of vector indexes, including creating, deleting, listing, and updating indexes, as well as inserting, upserting, deleting, and querying vectors within those indexes.

    Authentication is handled via Cloudflare API credentials (API key or token).

    const vectorize = new Vectorize({
    credentials: {
    accountId: "your-account-id",
    email: "your-email@example.com",
    apiKey: "your-api-key"
    }
    });

    // Create a new index
    await vectorize.createVectorizeIndex({ name: "my-index", description: "Test index", config: { ... } });

    // Insert vectors
    const ndjson = vectorize.toNDJSON([{ id: "vec1", values: [0.1, 0.2, 0.3] }]);
    await vectorize.insertVectorsIndex({ indexName: "my-index", ndjson });

    // Query vectors
    const result = await vectorize.queryVectors({
    indexName: "my-index",
    vector: [0.1, 0.2, 0.3],
    topK: 5
    });
    • All methods return Promises that resolve to the API response types.
    • NDJSON utilities are provided for bulk vector operations.
    • Error handling includes parsing Cloudflare error messages.
    Index

    Constructors

    Methods

    • Creates a new vectorize index with the specified parameters.

      Parameters

      • params: CreateVectorizeIndexParams

        The parameters for creating the vectorize index, including:

        • name: The name of the index.
        • description: A description of the index.
        • config: Configuration options for the index.

      Returns Promise<CreateVectorizeIndexResponse>

      A promise that resolves to the response of the create vectorize index operation.

    • Deletes a vectorize index by its name.

      Parameters

      • params: DeleteVectorizeIndexParams

        The parameters containing the index name to delete.

      Returns Promise<DeleteVectorizeIndexResponse>

      A promise that resolves with the response of the delete operation.

    • Deletes vectors from the specified index by their identifiers.

      Parameters

      • params: DeleteVectorsByIdentifierParams

        The parameters for deleting vectors by identifier.

        • indexName

          The name of the index from which to delete vectors.

        • ids

          An array of vector identifiers to delete.

      Returns Promise<DeleteVectorsByIdentifierResponse>

      A promise that resolves to the response of the delete operation.

    • Retrieves information about a specific vectorize index.

      Parameters

      • params: GetVectorizeIndexParams

        The parameters required to get the vectorize index, including the index name.

      Returns Promise<GetVectorizeIndexResponse>

      A promise that resolves to the response containing details of the vectorize index.

    • Retrieves detailed information about a vectorize index.

      Parameters

      • params: GetVectorizeIndexInfoParams

        The parameters containing the index name.

      Returns Promise<GetVectorizeIndexInfoResponse>

      The response from the API.

    • Retrieves vectors from the specified index by their unique identifiers.

      Parameters

      • params: GetVectorsByIdentifierParams

        The parameters for fetching vectors by identifier.

        • indexName

          The name of the index to query.

        • ids

          An array of unique identifiers for the vectors to retrieve.

      Returns Promise<GetVectorsByIdentifierResponse>

      A promise that resolves to the response containing the requested vectors.

    • Inserts vectors into a specified index in the Cloudflare Vectorize service.

      Parameters

      • params: InsertVectorizeIndexParams

        The parameters for inserting vectors.

        • indexName

          The name of the index to insert vectors into.

        • ndjson

          The NDJSON string containing the vectors to insert.

        • unparsableBehavior

          Optional behavior for handling unparsable vectors.

      Returns Promise<InsertVectorizeIndexResponse>

      A promise that resolves to the response of the insert operation.

    • Retrieves a list of vectorize indexes from the Cloudflare Vectorize API.

      Returns Promise<ListVectorizeIndexResponse>

      A promise that resolves to a ListVectorizeIndexResponse containing the vectorize index data.

      const indexes = await listVectorizeIndex();
      
    • Queries a vector index with the provided vector and optional filters.

      Parameters

      • params: QueryVectorsParams

        The parameters for querying vectors.

        • indexName

          The name of the vector index to query.

        • vector

          The query vector to search with.

        • filter

          Optional filter to apply to the query.

        • returnMetadata

          Specifies the metadata to return ("none" by default).

        • returnValues

          Optional flag to indicate if vector values should be returned.

        • topK

          The number of top results to return.

      Returns Promise<QueryVectorsResponse>

      A promise that resolves to the query response containing matched vectors and metadata.

    • Converts an array of objects into an NDJSON (Newline Delimited JSON) string.

      Each object in the input array is serialized to a JSON string and separated by a newline character.

      Parameters

      • items: object[]

        An array of objects to be converted to NDJSON format.

      Returns string

      A string representing the NDJSON serialization of the input objects.

    • Upserts vectors into the specified index.

      Sends a POST request to the {indexName}/upsert endpoint with NDJSON data. Optionally handles unparsable vectors according to the provided behavior.

      Parameters

      • params: UpsertVectorsParams

        The parameters for upserting vectors.

        • indexName

          The name of the index to upsert vectors into.

        • ndjson

          The NDJSON string containing vector data.

        • unparsableBehavior

          Optional behavior for handling unparsable vectors.

      Returns Promise<UpsertVectorsResponse>

      A promise that resolves to the upsert vectors response.