Skip to main content
Group a text collection into clusters labeled from your own vocabulary, then answer a query by walking that tree. Jev picks the most likely branch at each level and the retriever returns members of the best cluster, with the path it took.

Jump to the manifest

hierarchical-cluster-search.namespace.yaml: apply it with one API call, then read the walkthrough below to change it.

At a glance

How the pieces connect

Buckets hold what you upload, collections turn it into searchable documents, and retrievers answer queries over the collections.

Deploy it

1

Get the manifest

2

Validate it

Validate runs every check apply runs and creates nothing. Fix each entry in errors, then run it again.
3

Apply it

Apply creates every resource in one call. wait_for_seed=true also waits until the sample objects are processed, so the first query below has documents to return.
The response lists each resource with its outcome in resources. Apply refuses a resource that already exists and rolls the whole apply back, so to apply the file again over this namespace add ?mode=create_missing, which creates only what is missing.

Run the first query

Look up the namespace id by name, then run content-search. Check status and warnings along with documents: a run that times out still answers 200, with status degraded.

Add your own data

Each object you add to a bucket is processed by every collection that reads it. This adds one object to content. NAMESPACE_ID is the id from the namespace lookup above.
The object is PENDING until processing finishes, then COMPLETED or FAILED. Buckets and objects covers object states, retries and duplicates.

Retrievers

Plain vector search over content-text. Answers as soon as the seed is indexed. Stages: feature_search Searches: content-text

browse-content-tree

Walks the content-tree clusters top-down with Jev and returns members of the best leaf cluster. Answers after the cluster has run once. Stages: agent_search Searches: content-tree

Collections

Each collection runs one extractor over a bucket, or over another collection’s documents.
text_extractor@v1 over bucket content. Feeds content-search and the content-tree cluster.Reads bucket content with text_extractor v1.Inputs: text ← contentCopied onto each document: headline

Also created

Clusters
  • content-tree: Groups content-text by meaning and labels every cluster from a fixed vocabulary, so a retriever can walk the groups top-down.

The manifest

Every resource above comes from this file. Change it and apply it again with ?mode=upsert to update what exists. Manifests documents each field.
hierarchical-cluster-search.namespace.yaml

Hand it to an agent

Paste this prompt into Claude Code, Cursor or another coding agent. To give the agent this whole page instead, use Copy page in the menu at the top of the page, or point it at the page’s Markdown at https://mixpeek.com/docs/templates/hierarchical-cluster-search.md.
Prompt

How it works

Hierarchical search first picks the part of the corpus most likely to hold the answer, then returns documents from inside it. This template builds it beside plain vector search over the same data.
  1. content-text embeds each object’s content with text_extractor into the multilingual_e5_large_instruct_v1 feature. content-search searches that feature directly.
  2. The content-tree cluster groups those vectors with k-means. Jev then labels every cluster by picking one name from candidate_labels, and stores the pick’s probability as label_confidence.
  3. A cluster run writes the content-tree output collection: one centroid document per cluster (is_centroid, cluster_id, label, parent_cluster_id) plus a copy of every member document with its source’s vector.
  4. browse-content-tree runs an agent_search stage with the cluster_navigation strategy over that collection. It builds the tree from parent_cluster_id and asks Jev at each level which child cluster most likely answers the query.
Apply creates the cluster but does not run it, so browse-content-tree returns no documents until the first run.

Run the cluster

1

Start a run

Look up the cluster id by name, then execute it. The call returns a task.
cURL
2

Wait for it to finish

Poll the task until status is COMPLETED, COMPLETED_WITH_ERRORS, FAILED or CANCELED.
cURL
3

Walk the tree

Run browse-content-tree with the same query you gave content-search.
cURL

Read the path Jev took

The stage records its walk under stage_statistics.stages.browse.metadata: Each returned document carries cluster_path and cluster_path_score. A path’s score is the geometric mean of its decision probabilities, so a shallow leaf and a deep leaf compare fairly. If error says no centroid documents were found, the cluster has not completed a run yet.

Why these settings

  • n_clusters: 3 matches the seed: twelve scripts in three themes (sports, cooking, ads).
  • hierarchical: true with max_hierarchy_depth: 2 asks for sub-clusters under each top-level cluster. A cluster splits only when it holds at least twice min_cluster_size members. k-means takes no min_cluster_size, so the default of 50 applies, and the twelve seed documents give a one-level tree.
  • provider: typesafe and model_name: jev-latest label each cluster by choosing from candidate_labels. Jev reads text only, so labeling_inputs maps the document’s text field. Jev needs 2 to 255 labels; sub-clusters are labeled from the same list, so list names for every level.
  • beam_width: 2 keeps two paths per level. 1 is greedy descent. A wider beam lets a later level correct an ambiguous early choice.
  • max_leaf_clusters: 1 returns members of the best leaf only. Raise it when a query can span topics.
  • timeout_seconds: 20 keeps the stage under the executor’s 25-second stage ceiling.

Variations

Each change below edits the manifest. Apply it again with ?mode=upsert, then run the cluster again.

Get a second level

HDBSCAN accepts min_cluster_size, so it controls when a cluster splits. With min_cluster_size: 5, a cluster with 10 or more members splits again. HDBSCAN picks the number of clusters itself and marks outliers as noise, so it suits a few hundred documents or more.
content-tree vector_config

Describe each label

candidate_labels also takes a map of label to a one-line description. Jev reads the description with the label, which helps when two names are close.
content-tree llm_labeling

Let a generative model name the clusters

Without candidate_labels, a generative model writes a label and a summary for each cluster. The walk shows the summary to Jev as the option’s description, which helps routing.
content-tree llm_labeling

Search first, then keep hits in the chosen clusters

The member copies in content-tree carry their source vectors, so a feature_search stage can run before the walk. agent_search then keeps the documents inside the chosen clusters, in search order, and drops centroids.
browse-content-tree stages
Do not set enrich_source_collection: true on the cluster for this. With it, the run writes cluster_id onto the source documents and creates no output collection, so there are no centroid documents for the walk to read.

Keep the tree current

A cluster run is a snapshot. Execute the cluster again after a batch of new objects is processed, as in Run the cluster.