@valkey/valkey-glide
    Preparing search index...

    Module for Vector Search commands.

    Index

    Constructors

    Methods

    • Runs a search query on an index, and perform aggregate transformations on the results.

      Parameters

      Returns Promise<FtAggregateReturnType>

      Results of the last stage of the pipeline.

      const options: FtAggregateOptions = {
      loadFields: ["__key"],
      clauses: [
      {
      type: "GROUPBY",
      properties: ["@condition"],
      reducers: [
      {
      function: "TOLIST",
      args: ["__key"],
      name: "bicycles",
      },
      ],
      },
      ],
      };
      const result = await GlideFt.aggregate(client, "myIndex", "*", options);
      console.log(result); // Output:
      // [
      // [
      // {
      // key: "condition",
      // value: "refurbished"
      // },
      // {
      // key: "bicycles",
      // value: [ "bicycle:9" ]
      // }
      // ],
      // [
      // {
      // key: "condition",
      // value: "used"
      // },
      // {
      // key: "bicycles",
      // value: [ "bicycle:1", "bicycle:2", "bicycle:3" ]
      // }
      // ],
      // [
      // {
      // key: "condition",
      // value: "new"
      // },
      // {
      // key: "bicycles",
      // value: [ "bicycle:0", "bicycle:5" ]
      // }
      // ]
      // ]
    • Adds an alias for an index. The new alias name can be used anywhere that an index name is required.

      Parameters

      Returns Promise<"OK">

      "OK"

      // Example usage of FT.ALIASADD to add an alias for an index.
      await GlideFt.aliasadd(client, "index", "alias"); // "OK"
    • Deletes an existing alias for an index.

      Parameters

      Returns Promise<"OK">

      "OK"

      // Example usage of FT.ALIASDEL to delete an existing alias.
      await GlideFt.aliasdel(client, "alias"); // "OK"
    • Updates an existing alias to point to a different physical index. This command only affects future references to the alias.

      Parameters

      Returns Promise<"OK">

      "OK"

      // Example usage of FT.ALIASUPDATE to update an alias to point to a different index.
      await GlideFt.aliasupdate(client, "newAlias", "index"); // "OK"
    • Creates an index and initiates a backfill of that index.

      Parameters

      • client: GlideClient | GlideClusterClient

        The client to execute the command.

      • indexName: GlideString

        The index name for the index to be created.

      • schema: Field[]

        The fields of the index schema, specifying the fields and their types.

      • Optionaloptions: FtCreateOptions

        (Optional) Options for the FT.CREATE command. See FtCreateOptions.

      Returns Promise<"OK">

      If the index is successfully created, returns "OK".

      // Example usage of FT.CREATE to create a 6-dimensional JSON index using the HNSW algorithm
      await GlideFt.create(client, "json_idx1", [{
      type: "VECTOR",
      name: "$.vec",
      alias: "VEC",
      attributes: {
      algorithm: "HNSW",
      type: "FLOAT32",
      dimension: 6,
      distanceMetric: "L2",
      numberOfEdges: 32,
      },
      }], {
      dataType: "JSON",
      prefixes: ["json:"]
      });
    • Deletes an index and associated content. Indexed document keys are unaffected.

      Parameters

      Returns Promise<"OK">

      "OK"

      // Example usage of FT.DROPINDEX to drop an index
      await GlideFt.dropindex(client, "json_idx1"); // "OK"
    • Returns information about a given index.

      Parameters

      Returns Promise<FtInfoReturnType>

      Nested maps with info about the index. See example for more details.

      const info = await GlideFt.info(client, "myIndex");
      console.log(info); // Output:
      // {
      // index_name: 'myIndex',
      // index_status: 'AVAILABLE',
      // key_type: 'JSON',
      // creation_timestamp: 1728348101728771,
      // key_prefixes: [ 'json:' ],
      // num_indexed_vectors: 0,
      // space_usage: 653471,
      // num_docs: 0,
      // vector_space_usage: 653471,
      // index_degradation_percentage: 0,
      // fulltext_space_usage: 0,
      // current_lag: 0,
      // fields: [
      // {
      // identifier: '$.vec',
      // type: 'VECTOR',
      // field_name: 'VEC',
      // option: '',
      // vector_params: {
      // data_type: 'FLOAT32',
      // initial_capacity: 1000,
      // current_capacity: 1000,
      // distance_metric: 'L2',
      // dimension: 6,
      // block_size: 1024,
      // algorithm: 'FLAT'
      // }
      // },
      // {
      // identifier: 'name',
      // type: 'TEXT',
      // field_name: 'name',
      // option: ''
      // },
      // ]
      // }
    • Runs an aggregate query and collects performance profiling information.

      Parameters

      • client: GlideClient | GlideClusterClient

        The client to execute the command.

      • indexName: GlideString

        The index name.

      • query: GlideString

        The text query to search.

      • Optionaloptions: DecoderOption & (FtAggregateOptions & { limited?: boolean | undefined; })

        (Optional) See FtAggregateOptions and DecoderOption. Additionally:

        • limited (Optional) - Either provide a full verbose output or some brief version.

      Returns Promise<[FtAggregateReturnType, Record<string, number>]>

      A two-element array. The first element contains results of the aggregate query being profiled, the second element stores profiling information.

      // Example of running profile on an aggregate query
      const options: FtAggregateOptions = {
      loadFields: ["__key"],
      clauses: [
      {
      type: "GROUPBY",
      properties: ["@condition"],
      reducers: [
      {
      function: "TOLIST",
      args: ["__key"],
      name: "bicycles",
      },
      ],
      },
      ],
      };
      const result = await GlideFt.profileAggregate(client, "myIndex", "*", options);
      console.log(result); // Output:
      // result[0] contains `FT.AGGREGATE` response with the given query
      // result[1] contains profiling data as a `Record<string, number>`
    • Runs a search query and collects performance profiling information.

      Parameters

      • client: GlideClient | GlideClusterClient

        The client to execute the command.

      • indexName: GlideString

        The index name.

      • query: GlideString

        The text query to search.

      • Optionaloptions: DecoderOption & (FtSearchOptions & { limited?: boolean | undefined; })

        (Optional) See FtSearchOptions and DecoderOption. Additionally:

        • limited (Optional) - Either provide a full verbose output or some brief version.

      Returns Promise<[FtSearchReturnType, Record<string, number>]>

      A two-element array. The first element contains results of the search query being profiled, the second element stores profiling information.

      // Example of running profile on a search query
      const vector = Buffer.alloc(24);
      const result = await GlideFt.profileSearch(client, "json_idx1", "*=>[KNN 2 @VEC $query_vec]", {params: [{key: "query_vec", value: vector}]});
      console.log(result); // Output:
      // result[0] contains `FT.SEARCH` response with the given query
      // result[1] contains profiling data as a `Record<string, number>`
    • Uses the provided query expression to locate keys within an index. Once located, the count and/or content of indexed fields within those keys can be returned.

      Parameters

      Returns Promise<FtSearchReturnType>

      A two-element array, where the first element is the number of documents in the result set, and the second element has the format: GlideRecord<GlideRecord<GlideString>>: a mapping between document names and a map of their attributes.

      If count or limit with values {offset: 0, count: 0} is set, the command returns array with only one element: the number of documents.

      //
      const vector = Buffer.alloc(24);
      const result = await GlideFt.search(client, "json_idx1", "*=>[KNN 2 @VEC $query_vec]", {params: [{key: "query_vec", value: vector}]});
      console.log(result); // Output:
      // [
      // 2,
      // [
      // {
      // key: "json:2",
      // value: [
      // {
      // key: "$",
      // value: '{"vec":[1.1,1.2,1.3,1.4,1.5,1.6]}',
      // },
      // {
      // key: "__VEC_score",
      // value: "11.1100006104",
      // },
      // ],
      // },
      // {
      // key: "json:0",
      // value: [
      // {
      // key: "$",
      // value: '{"vec":[1,2,3,4,5,6]}',
      // },
      // {
      // key: "__VEC_score",
      // value: "91",
      // },
      // ],
      // },
      // ],
      // ]