Zvec Node.js API Reference
    Preparing search index...

    Interface ZVecCollection

    Represents a collection in Zvec.

    interface ZVecCollection {
        path: string;
        schema: ZVecCollectionSchema;
        options: ZVecCollectionOptions;
        stats: { docCount: number; indexCompleteness: Record<string, number> };
        insertSync(docs: ZVecDocInput): ZVecStatus;
        insertSync(docs: ZVecDocInput[]): ZVecStatus[];
        upsertSync(docs: ZVecDocInput): ZVecStatus;
        upsertSync(docs: ZVecDocInput[]): ZVecStatus[];
        updateSync(docs: ZVecDocInput): ZVecStatus;
        updateSync(docs: ZVecDocInput[]): ZVecStatus[];
        deleteSync(ids: string): ZVecStatus;
        deleteSync(ids: string[]): ZVecStatus[];
        deleteByFilterSync(filter: string): ZVecStatus;
        deleteByFilter(filter: string): Promise<ZVecStatus>;
        querySync(params: ZVecQuery): ZVecDoc[];
        query(params: ZVecQuery): Promise<ZVecDoc[]>;
        multiQuerySync(params: ZVecMultiQuery): ZVecDoc[];
        multiQuery(params: ZVecMultiQuery): Promise<ZVecDoc[]>;
        groupByQuerySync(params: ZVecGroupByQuery): ZVecGroupResult[];
        groupByQuery(params: ZVecGroupByQuery): Promise<ZVecGroupResult[]>;
        fetchSync(ids: string | string[]): Record<string, ZVecDoc>;
        fetchSync(
            params: {
                ids: string | string[];
                outputFields?: string[];
                includeVector?: boolean;
            },
        ): Record<string, ZVecDoc>;
        iterDocsSync(options?: ZVecIteratorOptions): ZVecDocIterator;
        optimizeSync(options?: ZVecOptimizeOptions): void;
        optimize(options?: ZVecOptimizeOptions): Promise<void>;
        closeSync(): void;
        destroySync(): void;
        addColumnSync(
            params: {
                fieldSchema: ZVecFieldSchema;
                expression?: string;
                options?: ZVecAddColumnOptions;
            },
        ): void;
        dropColumnSync(fieldName: string): void;
        alterColumnSync(
            params: {
                columnName: string;
                newColumnName?: string;
                fieldSchema?: ZVecFieldSchema;
                options?: ZVecAlterColumnOptions;
            },
        ): void;
        createIndexSync(
            params: {
                fieldName: string;
                indexParams:
                    | ZVecFlatIndexParams
                    | ZVecHnswIndexParams
                    | ZVecHnswRabitqIndexParams
                    | ZVecIVFIndexParams
                    | ZVecIvfRabitqIndexParams
                    | ZVecDiskAnnIndexParams
                    | ZVecInvertIndexParams
                    | ZVecFtsIndexParams;
                indexOptions?: ZVecCreateIndexOptions;
            },
        ): void;
        dropIndexSync(fieldName: string): void;
    }
    Index

    Methods

    • Inserts a single document into the collection.

      Parameters

      Returns ZVecStatus

      The status of the operation.

    • Inserts a batch of documents into the collection.

      Parameters

      Returns ZVecStatus[]

      An array of statuses of the operation.

    • Inserts a single document into the collection, or updates it if it already exists based on its ID.

      Parameters

      Returns ZVecStatus

      The status of the operation.

    • Inserts a batch of documents into the collection, or updates them if they already exist based on their ID.

      Parameters

      Returns ZVecStatus[]

      An array of statuses of the operation.

    • Updates a single existing document by ID. Only specified fields and vectors are updated; others remain unchanged.

      Parameters

      • docs: ZVecDocInput

        A single document containing the updated data.

      Returns ZVecStatus

      The status of the operation.

    • Updates multiple existing documents by ID. Only specified fields and vectors are updated; others remain unchanged.

      Parameters

      • docs: ZVecDocInput[]

        An array of documents containing the updated data.

      Returns ZVecStatus[]

      An array of statuses of the operation.

    • Deletes a single document by its ID.

      Parameters

      • ids: string

        A single document ID to delete.

      Returns ZVecStatus

      The status of the operation.

    • Deletes multiple documents by their IDs.

      Parameters

      • ids: string[]

        An array of document IDs to delete.

      Returns ZVecStatus[]

      An array of statuses of the operation.

    • Deletes documents based on a filter expression.

      Parameters

      • filter: string

        A string representing the filter expression.

      Returns ZVecStatus

      The status of the operation.

    • Asynchronously deletes documents based on a filter expression.

      Parameters

      • filter: string

        A string representing the filter expression.

      Returns Promise<ZVecStatus>

      A promise that resolves with the status of the operation.

    • Performs a search query against the collection.

      Parameters

      Returns ZVecDoc[]

      An array of documents matching the query.

    • Asynchronously performs a search query against the collection.

      Parameters

      Returns Promise<ZVecDoc[]>

      A promise that resolves with an array of documents matching the query.

    • Performs multiple searches against the collection and merges their candidates.

      Parameters

      Returns ZVecDoc[]

      An array of documents matching the combined query.

    • Asynchronously performs multiple searches against the collection and merges their candidates.

      Parameters

      Returns Promise<ZVecDoc[]>

      A promise that resolves with an array of documents matching the combined query.

    • Fetches documents by their IDs.

      Parameters

      • ids: string | string[]

        A single document ID or an array of document IDs to fetch.

      Returns Record<string, ZVecDoc>

      An object mapping the requested IDs to their corresponding documents. If an ID is not found, it will not be present in the returned object.

    • Fetches documents by their IDs.

      Parameters

      • params: { ids: string | string[]; outputFields?: string[]; includeVector?: boolean }

        Fetch parameters.

        • ids: string | string[]

          A single document ID or an array of document IDs to fetch.

        • OptionaloutputFields?: string[]

          Scalar fields to include. If undefined, all scalar fields are returned. An empty array returns no scalar fields.

        • OptionalincludeVector?: boolean

          Whether to include vector data in fetched documents. Defaults to true.

      Returns Record<string, ZVecDoc>

      An object mapping the requested IDs to their corresponding documents. If an ID is not found, it will not be present in the returned object.

    • Traverse all documents using an isolated snapshot created when this method is called.

      Documents written after the iterator is created are not visible to it. On writable collections, creating the snapshot may seal the current writing segment. Traversal order is unspecified.

      While an iterator is open, collection close/destroy, optimize, index DDL, and column DDL operations are rejected. Writes, queries, and fetches remain available. Exhaust the iterator, exit its for...of loop, or call closeSync() to release this restriction.

      This is a synchronous API and may block the Node.js event loop while loading and converting documents.

      Parameters

      Returns ZVecDocIterator

      A synchronous document iterator.

    • Optimizes the collection's internal structures for better performance.

      Parameters

      Returns void

      If the operation fails.

    • Asynchronously optimizes the collection's internal structures for better performance.

      Parameters

      Returns Promise<void>

      A promise that resolves when optimization is complete.

      If the operation fails.

    • Closes the collection and releases its resources. After calling this method, the collection object should not be used.

      Returns void

      If the operation fails.

    • Permanently deletes the collection from disk. After calling this method, the collection object should not be used.

      Returns void

      If the operation fails.

    • Adds a new column to the collection.

      Parameters

      • params: {
            fieldSchema: ZVecFieldSchema;
            expression?: string;
            options?: ZVecAddColumnOptions;
        }

        An object containing the parameters for the operation.

        • fieldSchema: ZVecFieldSchema

          The schema definition for the new column.

        • Optionalexpression?: string

          Optional expression to compute values for existing documents.

        • Optionaloptions?: ZVecAddColumnOptions

          Optional parameters for the operation.

      Returns void

      If the operation fails.

    • Permanently deletes a column from the collection. After dropping, the data and schema for this column are removed.

      Parameters

      • fieldName: string

        The name of the column to drop.

      Returns void

      If the operation fails.

    • Alters an existing column in the collection. You can either rename the column or modify its schema.

      Parameters

      • params: {
            columnName: string;
            newColumnName?: string;
            fieldSchema?: ZVecFieldSchema;
            options?: ZVecAlterColumnOptions;
        }

        An object containing the parameters for the operation.

        • columnName: string

          The current name of the column to alter.

        • OptionalnewColumnName?: string

          The new name for the column (mutually exclusive with fieldSchema).

        • OptionalfieldSchema?: ZVecFieldSchema

          The new schema definition for the column (mutually exclusive with newColumnName).

        • Optionaloptions?: ZVecAlterColumnOptions

          Optional parameters for the operation.

      Returns void

      If the operation fails.

    • Drops (removes) an existing index from the collection.

      Parameters

      • fieldName: string

        The name of the column whose index should be dropped.

      Returns void

      If the operation fails.

    Properties

    path: string

    Gets the file system path associated with this collection.

    Gets the schema defining the structure of this collection.

    Gets the options used when this collection was opened/created.

    stats: { docCount: number; indexCompleteness: Record<string, number> }

    Gets statistics about this collection.