package valkey

  1. Overview
  2. Docs

Module Valkey.SearchSource

Typed helpers for the Valkey Search module.

Valkey Search commands operate on indexes rather than on Valkey key slots. The wrappers here therefore route through a random node in cluster mode. Metadata writes are always sent to a primary. Reads also default to primaries; pass ~read_from only when the application accepts replica/index lag.

Sourcetype data_type =
  1. | Hash
  2. | Json
Sourcetype text_suffix_trie =
  1. | Suffix_default
  2. | With_suffix_trie
  3. | No_suffix_trie
Sourcetype distance_metric =
  1. | L2
  2. | Ip
  3. | Cosine
Sourcetype field
Sourceval text : ?alias:string -> ?sortable:bool -> ?no_stem:bool -> ?suffix_trie:text_suffix_trie -> ?weight:float -> string -> field
Sourceval tag : ?alias:string -> ?sortable:bool -> ?separator:char -> ?case_sensitive:bool -> string -> field
Sourceval numeric : ?alias:string -> ?sortable:bool -> string -> field
Sourceval vector_flat : ?alias:string -> ?sortable:bool -> ?initial_cap:int -> dim:int -> distance_metric:distance_metric -> string -> field
Sourceval vector_hnsw : ?alias:string -> ?sortable:bool -> ?initial_cap:int -> ?m:int -> ?ef_construction:int -> ?ef_runtime:int -> dim:int -> distance_metric:distance_metric -> string -> field
Sourcetype offsets =
  1. | With_offsets
  2. | No_offsets
Sourcetype stopwords =
  1. | Default_stopwords
  2. | No_stopwords
  3. | Stopwords of string list
Sourcetype create_options = {
  1. data_type : data_type;
  2. prefixes : string list;
  3. score : float option;
  4. language : string option;
  5. min_stem_size : int option;
  6. offsets : offsets;
  7. stopwords : stopwords;
  8. punctuation : string option;
  9. skip_initial_scan : bool;
}
Sourceval default_create_options : create_options
Sourceval create : ?timeout:float -> ?options:create_options -> Client.t -> index:string -> schema:field list -> (unit, Connection_error.t) result

Create an index with FT.CREATE.

Sourceval drop_index : ?timeout:float -> Client.t -> string -> (unit, Connection_error.t) result

Drop an index with FT.DROPINDEX.

Sourceval list_indexes : ?timeout:float -> ?read_from:Router.Read_from.t -> Client.t -> (string list, Connection_error.t) result

List the indexes in the selected database with FT._LIST.

Sourcetype shard_policy =
  1. | All_shards
  2. | Some_shards
Sourcetype consistency =
  1. | Consistent
  2. | Inconsistent
Sourcetype info_scope =
  1. | Local
  2. | Primary
  3. | Cluster
Sourcetype info_options = {
  1. scope : info_scope;
  2. shard_policy : shard_policy;
  3. consistency : consistency;
}
Sourceval default_info_options : info_options
Sourceval info_raw : ?timeout:float -> ?read_from:Router.Read_from.t -> ?options:info_options -> Client.t -> string -> ((string * Resp3.t) list, Connection_error.t) result

Return the raw FT.INFO key/value pairs. The Search module still evolves quickly, so the library keeps the full server payload instead of baking every metric into a lossy record.

Sourcetype sort_direction =
  1. | Asc
  2. | Desc
Sourcetype return_field = {
  1. field : string;
  2. alias : string option;
}
Sourceval return_field : ?alias:string -> string -> return_field
Sourcetype search_sort = {
  1. by : string;
  2. direction : sort_direction option;
}
Sourceval search_sort : ?direction:sort_direction -> string -> search_sort
Sourcetype search_options = {
  1. shard_policy : shard_policy;
  2. consistency : consistency;
  3. dialect : int option;
  4. inorder : bool;
  5. limit : (int * int) option;
  6. no_content : bool;
  7. params : (string * string) list;
  8. return_fields : return_field list option;
  9. slop : int option;
  10. sort_by : search_sort option;
  11. timeout_ms : int option;
  12. verbatim : bool;
  13. with_sort_keys : bool;
}
Sourceval default_search_options : search_options
Sourcetype document = {
  1. key : string;
  2. sort_key : Resp3.t option;
  3. fields : (string * Resp3.t) list;
}
Sourcetype search_result = {
  1. total : int64;
  2. documents : document list;
}

Run FT.SEARCH. Field values are kept as Resp3.t so HASH, JSON, vector-distance, and future module payloads remain representable without string coercion.

Sourcetype load =
  1. | Load_all
  2. | Load_fields of string list
Sourcetype reducer =
  1. | Count
  2. | Count_distinct of string
  3. | Sum of string
  4. | Min of string
  5. | Max of string
  6. | Avg of string
  7. | Stddev of string
  8. | Custom_reducer of {
    1. name : string;
    2. args : string list;
    }
Sourcetype group_reducer = {
  1. reducer : reducer;
  2. reducer_alias : string option;
}
Sourceval group_reducer : ?alias:string -> reducer -> group_reducer
Sourcetype aggregate_sort = {
  1. expression : string;
  2. sort_direction : sort_direction option;
}
Sourceval aggregate_sort : ?direction:sort_direction -> string -> aggregate_sort
Sourcetype aggregate_stage =
  1. | Apply of {
    1. expression : string;
    2. alias : string;
    }
  2. | Filter of string
  3. | Group_by of {
    1. fields : string list;
    2. reducers : group_reducer list;
    }
  4. | Limit of {
    1. offset : int;
    2. count : int;
    }
  5. | Sort_by of {
    1. fields : aggregate_sort list;
    2. max : int option;
    }
Sourcetype aggregate_options = {
  1. dialect : int option;
  2. inorder : bool;
  3. load : load option;
  4. params : (string * string) list;
  5. slop : int option;
  6. timeout_ms : int option;
  7. verbatim : bool;
  8. stages : aggregate_stage list;
}
Sourceval default_aggregate_options : aggregate_options
Sourcetype aggregate_result = {
  1. header : Resp3.t;
  2. rows : (string * Resp3.t) list list;
}
Sourceval aggregate : ?timeout:float -> ?read_from:Router.Read_from.t -> ?options:aggregate_options -> Client.t -> index:string -> query:string -> (aggregate_result, Connection_error.t) result

Run FT.AGGREGATE. The first response element has no stable semantics in Valkey's command reference, so it is exposed as header and row records are decoded as field/value pairs.

Sourcemodule For_testing : sig ... end