|
| 1 | +--- |
| 2 | +title: Query profiling |
| 3 | +sidebar_position: 95 |
| 4 | +image: og/docs/howto.jpg |
| 5 | +description: "Profile search queries to get per-shard timing breakdowns for vector search, keyword scoring, and filter evaluation." |
| 6 | +--- |
| 7 | + |
| 8 | +import FilteredTextBlock from '@site/src/components/Documentation/FilteredTextBlock'; |
| 9 | +import PyCode from '!!raw-loader!/_includes/code/howto/search.profile.py'; |
| 10 | +import QueryProfileNote from '/_includes/feature-notes/query-profile.mdx'; |
| 11 | + |
| 12 | +<QueryProfileNote/> |
| 13 | + |
| 14 | +Query profiling provides per-shard timing breakdowns for search queries. Enable it on any search request to see how long each phase takes — vector search, keyword scoring, filter evaluation, object retrieval — broken down by shard and cluster node. |
| 15 | + |
| 16 | +Profiling uses the same instrumentation as [slow query logging](/deploy/configuration/logging.md#slow-query-logging). It adds minimal overhead when enabled and zero overhead when disabled. |
| 17 | + |
| 18 | +## Enable profiling |
| 19 | + |
| 20 | +Add `query_profile=True` to `MetadataQuery`, or include `"query_profile"` in the metadata list: |
| 21 | + |
| 22 | +<FilteredTextBlock |
| 23 | + text={PyCode} |
| 24 | + startMarker="# START ProfileNearVector" |
| 25 | + endMarker="# END ProfileNearVector" |
| 26 | + language="python" |
| 27 | +/> |
| 28 | + |
| 29 | +Profile data is returned on the response object at `response.query_profile`, not on individual result objects. It represents the entire query across all shards. |
| 30 | + |
| 31 | +## Supported search types |
| 32 | + |
| 33 | +| Search type | Profile sections | Query methods | |
| 34 | +| :---------- | :--------------- | :------------ | |
| 35 | +| Vector search | `vector` | `near_vector`, `near_object`, `near_text`, `near_image`, etc. | |
| 36 | +| Keyword search (BM25) | `keyword` | `bm25` | |
| 37 | +| Hybrid search | `vector` + `keyword` | `hybrid` | |
| 38 | +| Object fetch | `object` | `fetch_objects` | |
| 39 | +| Any search + filters | Includes filter metrics | Add `filters` to any search | |
| 40 | +| Any search + groupBy | Profile at query level | Add `group_by` to any search | |
| 41 | + |
| 42 | +### BM25 example |
| 43 | + |
| 44 | +<FilteredTextBlock |
| 45 | + text={PyCode} |
| 46 | + startMarker="# START ProfileBM25" |
| 47 | + endMarker="# END ProfileBM25" |
| 48 | + language="python" |
| 49 | +/> |
| 50 | + |
| 51 | +### Hybrid example |
| 52 | + |
| 53 | +Hybrid search produces both `vector` and `keyword` profile sections per shard: |
| 54 | + |
| 55 | +<FilteredTextBlock |
| 56 | + text={PyCode} |
| 57 | + startMarker="# START ProfileHybrid" |
| 58 | + endMarker="# END ProfileHybrid" |
| 59 | + language="python" |
| 60 | +/> |
| 61 | + |
| 62 | +## Response structure |
| 63 | + |
| 64 | +The profile is structured as: |
| 65 | + |
| 66 | +``` |
| 67 | +response.query_profile |
| 68 | + └── shards[] |
| 69 | + ├── name # Shard identifier (e.g. "shard_0") |
| 70 | + ├── node # Cluster node (e.g. "weaviate-0") |
| 71 | + └── searches # Dict of search type → profile |
| 72 | + ├── "vector" → details: { key: value, ... } |
| 73 | + ├── "keyword" → details: { key: value, ... } |
| 74 | + └── "object" → details: { key: value, ... } |
| 75 | +``` |
| 76 | + |
| 77 | +Each search type contains a `details` dict with string key-value pairs. The available metrics depend on the query type, index configuration, and filter usage. |
| 78 | + |
| 79 | +## Available metrics |
| 80 | + |
| 81 | +### General metrics |
| 82 | + |
| 83 | +| Metric | Description | Present when | |
| 84 | +| :----- | :---------- | :----------- | |
| 85 | +| `total_took` | Total time for this shard's search | Always | |
| 86 | +| `objects_took` | Time retrieving objects from storage | Always | |
| 87 | +| `sort_took` | Time sorting results | When sorting is applied | |
| 88 | + |
| 89 | +### Vector search metrics |
| 90 | + |
| 91 | +| Metric | Description | |
| 92 | +| :----- | :---------- | |
| 93 | +| `vector_search_took` | Time spent in vector index search | |
| 94 | +| `knn_search_layer_N_took` | Per-layer HNSW graph traversal time (N = layer number) | |
| 95 | +| `knn_search_rescore_took` | Time rescoring compressed vectors (PQ/BQ/SQ) | |
| 96 | +| `hnsw_flat_search` | Whether flat (brute-force) search was used instead of HNSW (`"true"` or `"false"`) | |
| 97 | + |
| 98 | +### Filter metrics |
| 99 | + |
| 100 | +| Metric | Description | |
| 101 | +| :----- | :---------- | |
| 102 | +| `filters_build_allow_list_took` | Time building the filter allow-list | |
| 103 | +| `filters_ids_matched` | Number of object IDs matching the filter | |
| 104 | + |
| 105 | +### BM25 keyword metrics |
| 106 | + |
| 107 | +| Metric | Description | |
| 108 | +| :----- | :---------- | |
| 109 | +| `kwd_method` | BM25 scoring method used (e.g., `blockmaxwand`) | |
| 110 | +| `kwd_time` | Total BM25 scoring time | |
| 111 | +| `kwd_1_tok_time` | Query tokenization time | |
| 112 | +| `kwd_3_term_time` | Term dictionary lookup time | |
| 113 | +| `kwd_4_bmw_time` | BlockMaxWAND scoring time | |
| 114 | +| `kwd_6_res_count` | Number of results from keyword scoring | |
| 115 | + |
| 116 | +## Example output |
| 117 | + |
| 118 | +A hybrid search on a 3-node cluster with filters produces profiles for both vector and keyword phases on each shard: |
| 119 | + |
| 120 | +``` |
| 121 | +Shard: shard_abc (node: weaviate-0) |
| 122 | + [keyword] |
| 123 | + kwd_method: blockmaxwand |
| 124 | + kwd_time: 242.75µs |
| 125 | + kwd_1_tok_time: 18.291µs |
| 126 | + kwd_3_term_time: 52.083µs |
| 127 | + kwd_4_bmw_time: 156.417µs |
| 128 | + total_took: 248.833µs |
| 129 | + [vector] |
| 130 | + filters_build_allow_list_took: 31.125µs |
| 131 | + filters_ids_matched: 847 |
| 132 | + knn_search_layer_0_took: 14µs |
| 133 | + objects_took: 153.542µs |
| 134 | + total_took: 198.666µs |
| 135 | + vector_search_took: 40.959µs |
| 136 | +
|
| 137 | +Shard: shard_def (node: weaviate-1) |
| 138 | + [keyword] |
| 139 | + kwd_method: blockmaxwand |
| 140 | + kwd_time: 189.333µs |
| 141 | + total_took: 195.25µs |
| 142 | + [vector] |
| 143 | + filters_build_allow_list_took: 27.458µs |
| 144 | + filters_ids_matched: 912 |
| 145 | + total_took: 172.417µs |
| 146 | + vector_search_took: 35.75µs |
| 147 | +``` |
| 148 | + |
| 149 | +## Multi-node behavior |
| 150 | + |
| 151 | +In multi-node clusters, the coordinator node aggregates profile data from all shards across all nodes. Each shard profile includes the `node` field identifying which cluster node executed that shard's search. This makes it straightforward to identify performance imbalances across nodes. |
| 152 | + |
| 153 | +## Performance impact |
| 154 | + |
| 155 | +- **When disabled (default):** Zero overhead. A single boolean check skips all profiling code paths. |
| 156 | +- **When enabled:** Adds timing instrumentation to each shard search. The overhead is small (microsecond-level timer reads) but measurable under high-throughput workloads. Use for debugging and optimization, not in production hot paths. |
| 157 | + |
| 158 | +## Limitations |
| 159 | + |
| 160 | +- **Response-level only:** Profile data is on `response.query_profile`, not on individual objects. It represents the entire query, not individual result objects. |
| 161 | +- **Search phases only:** Profiling covers vector search, keyword scoring, and filter evaluation. It does not include time spent in generative modules, rerankers, or post-processing. |
| 162 | +- **No per-object breakdown:** You get per-shard timing, not per-object timing. |
| 163 | +- **Metrics vary by query:** Not all metrics appear in every response. Available metrics depend on the search type, index type (HNSW vs. flat), compression settings, and whether filters are used. |
| 164 | + |
| 165 | +## Questions and feedback |
| 166 | + |
| 167 | +import DocsFeedback from '/_includes/docs-feedback.mdx'; |
| 168 | + |
| 169 | +<DocsFeedback/> |
0 commit comments