Skip to main content
Vector search finds the documents nearest to a query. Hierarchical search first finds the right part of your corpus, then searches inside it. This guide clusters a collection into a two-level hierarchy, labels every cluster from a fixed vocabulary, and answers queries by walking the tree top-down with Jev. The walk uses the cluster_navigation strategy of Agent Search. At each level, Jev returns a probability for every child cluster. The stage keeps the best few paths and returns members of the best leaf clusters.

1. Cluster into a hierarchy and label it

Set hierarchical: true to split each top-level cluster into sub-clusters. Give candidate_labels the names you want at both levels.
The run writes one centroid document per cluster into the cluster’s output collection. Each centroid carries label, label_confidence and parent_cluster_id.

2. Create a retriever that walks the tree

Point the retriever at the cluster’s output collection.

3. Query it

The stage metadata shows the path Jev took. chosen_clusters lists each leaf with its path and score, and navigation_trace lists the candidates and probabilities at every level.
That output is from a production run of “a hand-tied bouquet of flowers” against a product catalog: the stage returned 10 members, all food or home products, in 415 ms. Put a feature_search stage before agent_search to search first and then keep only the hits inside the chosen clusters. The order from the search is preserved. Member documents need a cluster field, so enrich the source collection with cluster assignments (enrich_source_collection: true) and set cluster_navigation.centroid_collection_ids to the collection holding the centroids.

Tuning

  • beam_width: 1 is greedy descent and makes one request per level. Wider beams let a later level correct an ambiguous early choice. All beams at one level share one request.
  • Summaries improve routing. Jev sees each centroid’s summary as the option’s description.
  • max_leaf_clusters above 1 returns neighbors of the best cluster, useful when a query spans topics.