When you run a MongoDB Vector Search query with the explain method, the query returns a
BSON document containing query plan and execution statistics that describe how the
query was run internally.
Syntax
db.<myCollection>.explain("<verbosity>").aggregate([    {      "$vectorSearch": {        "exact": true | false,        "filter": {<filter-specification>},        "index": "<index-name>",        "limit": <number-of-results>,        "numCandidates": <number-of-candidates>,        "path": "<field-to-search>",        "queryVector": [<array-of-numbers>],        "explainOptions": {          "traceDocumentIds": [<array-of-document-IDs>]        }      }    } ]) 
Verbosity
Verbosity mode controls the behavior of explain and the amount of
information returned. Value can be one of the following,
in order of decreasing verbosity:
| Information about the query plan including the  | |
| Information about the query plan including the  | |
| queryPlanner (default) | Information about the query plan. Does not include the
 | 
Explain Results
The explain method returns a BSON document with the following fields.
| Option | Type | Necessity | Purpose | 
|---|---|---|---|
| 
 | document | Optional | Describes the execution statistics for the collector. | 
| 
 | document | Optional | Contains useful metadata. | 
| 
 | document | Optional | Describes the execution statistics for the query. This is not
present at the the top level for  | 
| 
 | document | Optional | Details related to retrieving per-document data after
query execution. This is not returned for  | 
| 
 | document | Optional | Details the resource usage of the query when it was executed.
This is not returned for  | 
| 
 | array of objects | Optional | Tracing details, such as the following, about vectors in the specified documents: 
 | 
| 
 | array of objects | Optional | Per-Lucene segment details of  | 
collectors
The collectors is a BSON document with the following field:
| Field | Type | Necessity | Purpose | 
|---|---|---|---|
| 
 | document | Required | Statistics of all collectors of the query. Statistics reported represent either
the maximum value across all collectors used in the query or
a sum of the statistic across all the sub-collectors. The timing statistics are
summed to reflect the total time spent across all collectors
for the entire query. To learn more, see
 | 
allCollectorStats
The allCollectorStats is a BSON document that describes collector
statistics across all collectors specified in the query.
It contains the following keys:
| Field | Description | 
|---|---|
| 
 | Tracks the duration and number of results collected by the collector. | 
| 
 | Statistics tracking the total duration and the number of times a
 | 
| 
 | Statistics tracking the total duration and number of times a scorer was set on the collector. | 
metadata
The metadata contains helpful metadata, such as the following:
| Field | Type | Necessity | Purpose | 
|---|---|---|---|
| 
 | String | Optional | Current version of  | 
| 
 | String | Optional | Human readable label that identifies the  | 
| 
 | String | Optional | MongoDB Vector Search index used in the query. | 
| 
 | Document | Optional | Cursor options given to  | 
| 
 | Integer | Optional | Total number of documents in the index including deleted documents. | 
query
The explain response is a BSON document with keys and values
describing the execution statistics for the query. The explain
document in the result set contains the following fields:
| Field | Type | Necessity | Purpose | 
|---|---|---|---|
| 
 | string | Optional | Path to the queried embedding field, only if it isn't the root. | 
| 
 | string | Required | Name of the type of vector search query. See
 | 
| 
 | document | Required | Vector search query information. See  | 
| 
 | document | Optional | 
 | 
args
The explain response
contains information how the query was executed internally. The
args field includes the following details:
- Query type 
- A structured summary example for each query type 
- Query options in the structured summary 
The following sections describe the query types and the fields in the structured summaries:
- WrappedKnnQuery
- A wrapper query used for ANN vector search that combines multiple queries. The structured summary includes details on the following option: FieldTypeNecessityDescription- query- Array - Required - Array of sub-queries used in the vector search, typically containing - KnnFloatVectorQueryand- DocAndScoreQuery.
- KnnFloatVectorQuery
- A query type specific to ANN search on float vectors. The structured summary includes details on the following options: FieldTypeNecessityDescription- field- String - Required - The vector field path being searched. - k- Integer - Required - Number of nearest neighbors to retrieve. 
- DocAndScoreQuery
- A query type that handles document matching and scoring. The structured summary typically includes statistics about query execution. 
- ExactVectorSearchQuery
- A query type for ENN vector searches. The structured summary includes details on the following options: FieldTypeNecessityDescription- field- String - Required - The vector field path being searched. - similarityFunction- String - Required - The similarity function used ( - dotProduct,- cosine, or- euclidean).- filter- Document - Optional - Pre-filter query that limits the vector search scope. 
- BooleanQuery
- If you use a pre-filter in your vector search query, your explain results include the - BooleanQuerytype. To learn more about the fields for this type and other query types specific to your pre-filter query, refer to the Query Types on the MongoDB Search Explain Page.
stats
The explain response for executionStats and
allPlansExecution verbosity modes
includes a stats field that contains information on how much
time a query spends in various stages
of query execution.
Timing Breakdown
The timing breakdown describes execution statistics pertinent to an areas of query execution. The following fields show the timing breakdown:
| Field | Type | Description | 
|---|---|---|
| 
 | Long | |
| 
 | Document | Number of invocations of tasks included in this area. The value is a map of task names to their invocation count. | 
Areas of Query
Statistics are available for the following areas of query:
| Option | Description | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 
 | Statistics related to the execution of the vector search query. There are two tasks whose invocation counts are enumerated in this area: 
 The time spent in this area is related to the structure of the query, and is not based on the number of results that are iterated through and scored. For example:  | |||||||||||
| 
 | Statistics related to iterating over and matching result documents. This statistic shows the time it takes to determine which document is the next match. Time spent matching results can vary significantly depending on the nature of the query. There are two tasks whose invocation counts are enumerated in this area: 
 For example:  | |||||||||||
| 
 | Statistics related to scoring documents in the result set. There are two tasks whose invocation counts are enumerated in this area: 
 For example:  | 
resourceUsage
The resourceUsage document shows the resource used for running the query. It
contains the following fields:
| Field | Type | Necessity | Purpose | 
|---|---|---|---|
| 
 | Long | Required | Number of major page faults, which occur when the system can't find the required data in memory resulting in reading from the backing store such as disk, during query execution. | 
| 
 | Long | Required | Number of minor page faults, which occur when the data is in the page cache, but hasn't yet been mapped to the process' page table. | 
| 
 | Long | Required | Amount of CPU time, in milliseconds, spent in user space. | 
| 
 | Long | Required | Amount of CPU time, in milliseconds, spent in system space. | 
| 
 | Integer | Required | Maximum number of threads that  | 
| 
 | Integer | Required | Total number of batches that  | 
vectorTracing
The vectorTracing array contains list of objects, one per
document, which has the following details about the vectors in the
document:
| Field | Type | Necessity | Purpose | 
|---|---|---|---|
| 
 | Boolean | Required | Flag that specifies whether the traced vector was visited during query execution. | 
| 
 | String | Conditional | Reason for dropping the vector. This is present only if vector was visited and dropped from the results. Value can be: 
 | 
| 
 | Double | Conditional | Score associated with the vector. This is present only if vector was visited | 
| 
 | Integer | Required | Lucene segment number to which the vector belongs. To learn
more, see  | 
| 
 | Boolean | Conditional | Flag that specifies whether the vector is unreachable. This is present only if the vector is unreachable. | 
luceneVectorSegmentStats
The luceneVectorSegmentStats array of objects contain per-Lucene
segment breakdown of the $vectorSearch query execution.
Each segment is identified by a number and includes the parameters
that describe the query execution details.
{   "0": {     "executionType": "Approximate",     "approximateTimeMillis": 0.10825,     "filterMatchedDocsCount": 0,     "docCount": 100   },   "1": {     "executionType": "Exact",     "exactTimeMillis": 0.10825,     "filterMatchedDocsCount": 0,     "docCount": 55   },   "2": {     "executionType": "ApproximateToExactFallback",     "approximateTimeMillis": 0.10825,     "exactTimeMillis": 0.10825,     "filterMatchedDocsCount": 0,     "docCount": 55   } } 
| Field | Type | Necessity | Purpose | 
|---|---|---|---|
| 
 | String | Required | The execution strategy. Value can be one of the following: 
 | 
| 
 | Float | Conditional | Time (in milliseconds) for the approximate phase. This is
returned only for  | 
| 
 | Float | Conditional | Time (in milliseconds) for the Exact phase. This is returned
only for  | 
| 
 | Integer | Optional | The number of documents that matched the query filter if you specified a prefilter in the query. | 
| 
 | Integer | Required | Total number of documents in the segment. | 
Examples
The following examples use the explain method on sample ANN and ENN queries.
If you want to run the following examples in your own environment, you must
first complete the MongoDB Vector Search Quick Start
using mongosh.
allPlansExecution
The following example runs the explain method on an ANN and ENN vector search
query for the plot_embedding_voyage_3_large field with the allPlansExecution
verbosity mode.
db.embedded_movies.explain("allPlansExecution").aggregate([   {     "$vectorSearch": {       "index": "vector_index",       "path": "plot_embedding_voyage_3_large",       "queryVector": QUERY_EMBEDDING,       "numCandidates": 150,       "limit": 10     }   } ]) 
1 { 2   explainVersion: '1', 3   stages: [ 4     { 5       '$vectorSearch': { 6         index: 'vector_index', 7         path: 'plot_embedding_voyage_3_large', 8         queryVector: 'redacted', 9         numCandidates: 150, 10         limit: 10, 11         explain: { 12           query: { 13             type: 'WrappedKnnQuery', 14             args: { 15               query: [ 16                 { 17                   type: 'InstrumentableKnnFloatVectorQuery', 18                   args: { 19                     field: '$type:knnVector/plot_embedding_voyage_3_large', 20                     k: 150 21                   }, 22                   stats: { 23                     context: { millisElapsed: 0 }, 24                     match: { millisElapsed: 0 }, 25                     score: { millisElapsed: 0 } 26                   } 27                 }, 28                 { 29                   type: 'DocAndScoreQuery', 30                   args: {}, 31                   stats: { 32                     context: { 33                       millisElapsed: 1.378949, 34                       invocationCounts: { 35                         createWeight: Long('1'), 36                         createScorer: Long('4') 37                       } 38                     }, 39                     match: { 40                       millisElapsed: 0.341389, 41                       invocationCounts: { nextDoc: Long('152') } 42                     }, 43                     score: { 44                       millisElapsed: 0.205415, 45                       invocationCounts: { 46                         score: Long('150'), 47                         setMinCompetitiveScore: Long('26') 48                       } 49                     } 50                   } 51                 } 52               ] 53             }, 54             stats: { 55               context: { 56                 millisElapsed: 57.285674, 57                 invocationCounts: { 58                   vectorExecution: Long('1'), 59                   createWeight: Long('1'), 60                   createScorer: Long('4') 61                 } 62               }, 63               match: { 64                 millisElapsed: 0.341389, 65                 invocationCounts: { nextDoc: Long('152') } 66               }, 67               score: { 68                 millisElapsed: 0.205415, 69                 invocationCounts: { 70                   score: Long('150'), 71                   setMinCompetitiveScore: Long('26') 72                 } 73               } 74             } 75           }, 76           collectors: { 77             allCollectorStats: { 78               millisElapsed: 0.840381, 79               invocationCounts: { 80                 collect: Long('150'), 81                 competitiveIterator: Long('2'), 82                 setScorer: Long('2') 83               } 84             } 85           }, 86           metadata: { 87             mongotVersion: '1.54.0', 88             mongotHostName: '<hostname>.mongodb.net', 89             indexName: 'vector_index', 90             lucene: { totalSegments: 2, totalDocs: 3483 } 91           }, 92           resourceUsage: { 93             majorFaults: Long('0'), 94             minorFaults: Long('0'), 95             userTimeMs: Long('0'), 96             systemTimeMs: Long('0'), 97             maxReportingThreads: 1, 98             numBatches: 1 99           }, 100           luceneVectorSegmentStats: [ 101             { 102               id: '_0', 103               executionType: 'Approximate', 104               docCount: 1952, 105               approximateStage: { millisElapsed: 32.916505 } 106             }, 107             { 108               id: '_1', 109               executionType: 'Approximate', 110               docCount: 1531, 111               approximateStage: { millisElapsed: 8.661519 } 112             } 113           ] 114         } 115       }, 116       nReturned: Long('10'), 117       executionTimeMillisEstimate: Long('256') 118     }, 119     { 120       '$_internalSearchIdLookup': { 121         limit: Long('10'), 122         subPipeline: [ 123           { '$match': { _id: { '$eq': '_id placeholder' } } } 124         ], 125         totalDocsExamined: Long('10'), 126         totalKeysExamined: Long('10'), 127         numDocsFilteredByIdLookup: Long('0') 128       }, 129       nReturned: Long('10'), 130       executionTimeMillisEstimate: Long('256') 131     } 132   ], 133   queryShapeHash: '2E39BED257F2B59D3F8652E1A81A18B1140602C4E253DED9FE208D584EA00083', 134   serverInfo: { 135     host: '<hostname>.mongodb.net', 136     port: 27017, 137     version: '8.2.1-rc1', 138     gitVersion: '3312bdcf28aa65f5930005e21c2cb130f648b8c3' 139   }, 140   serverParameters: { 141     internalQueryFacetBufferSizeBytes: 104857600, 142     internalQueryFacetMaxOutputDocSizeBytes: 104857600, 143     internalLookupStageIntermediateDocumentMaxSizeBytes: 104857600, 144     internalDocumentSourceGroupMaxMemoryBytes: 104857600, 145     internalQueryMaxBlockingSortMemoryUsageBytes: 104857600, 146     internalQueryProhibitBlockingMergeOnMongoS: 0, 147     internalQueryMaxAddToSetBytes: 104857600, 148     internalDocumentSourceSetWindowFieldsMaxMemoryBytes: 104857600, 149     internalQueryFrameworkControl: 'trySbeRestricted', 150     internalQueryPlannerIgnoreIndexWithCollationForRegex: 1 151   }, 152   command: { 153     aggregate: 'embedded_movies', 154     pipeline: [ 155       { 156         '$vectorSearch': { 157           index: 'vector_index', 158           path: 'plot_embedding_voyage_3_large', 159           queryVector: [ 160             -0.034731735,  0.008558298,   -0.0153717, -0.029912498,  0.011549547, 161             ..., 162             -0.006688767,  0.047527634,  0.040714234 163           ], 164           numCandidates: 150, 165           limit: 10 166         } 167       } 168     ], 169     cursor: {}, 170     '$db': 'sample_mflix' 171   }, 172   ok: 1, 173   '$clusterTime': { 174     clusterTime: Timestamp({ t: 1759341228, i: 32 }), 175     signature: { 176       hash: Binary.createFromBase64('BsaUr/khHU1Fyl5/g8htqoavlU8=', 0), 177       keyId: Long('7553982574624768005') 178     } 179   }, 180   operationTime: Timestamp({ t: 1759341228, i: 32 }) 181 } 
db.embedded_movies.explain("allPlansExecution").aggregate([   {     "$vectorSearch": {       "index": "vector_index",       "path": "plot_embedding_voyage_3_large",       "queryVector": QUERY_EMBEDDING,       "exact": true,       "limit": 10     }   } ]) 
{   explainVersion: '1',   stages: [     {       '$vectorSearch': {         index: 'vector_index',         path: 'plot_embedding_voyage_3_large',         queryVector: 'redacted',         exact: true,         limit: 10,         explain: {           query: {             type: 'ExactVectorSearchQuery',             args: {               field: '$type:knnVector/plot_embedding_voyage_3_large',               similarityFunction: 'dotProduct',               filter: {                 type: 'DefaultQuery',                 args: { queryType: 'FieldExistsQuery' },                 stats: {                   context: {                     millisElapsed: 0.756254,                     invocationCounts: {                       createWeight: Long('1'),                       createScorer: Long('4')                     }                   },                   match: {                     millisElapsed: 3.835071,                     invocationCounts: { nextDoc: Long('3405') }                   },                   score: { millisElapsed: 0 }                 }               }             },             stats: {               context: {                 millisElapsed: 1.271846,                 invocationCounts: { createWeight: Long('1'), createScorer: Long('4') }               },               match: {                 millisElapsed: 7.699638,                 invocationCounts: { nextDoc: Long('3405') }               },               score: {                 millisElapsed: 139.077653,                 invocationCounts: {                   score: Long('3403'),                   setMinCompetitiveScore: Long('63')                 }               }             }           },           collectors: {             allCollectorStats: {               millisElapsed: 146.798572,               invocationCounts: {                 collect: Long('3403'),                 competitiveIterator: Long('2'),                 setScorer: Long('2')               }             }           },           metadata: {             mongotVersion: '1.54.0',             mongotHostName: '<hostname>.mongodb.net',             indexName: 'vector_index',             lucene: { totalSegments: 2, totalDocs: 3483 }           },           resourceUsage: {             majorFaults: Long('0'),             minorFaults: Long('0'),             userTimeMs: Long('0'),             systemTimeMs: Long('0'),             maxReportingThreads: 1,             numBatches: 1           }         }       },       nReturned: Long('10'),       executionTimeMillisEstimate: Long('208')     },     {       '$_internalSearchIdLookup': {         limit: Long('10'),         subPipeline: [           { '$match': { _id: { '$eq': '_id placeholder' } } }         ],         totalDocsExamined: Long('10'),         totalKeysExamined: Long('10'),         numDocsFilteredByIdLookup: Long('0')       },       nReturned: Long('10'),       executionTimeMillisEstimate: Long('208')     }   ],   queryShapeHash: '2E39BED257F2B59D3F8652E1A81A18B1140602C4E253DED9FE208D584EA00083',   serverInfo: {     host: '<hostname>.mongodb.net',     port: 27017,     version: '8.2.1-rc1',     gitVersion: '3312bdcf28aa65f5930005e21c2cb130f648b8c3'   },   serverParameters: {     internalQueryFacetBufferSizeBytes: 104857600,     internalQueryFacetMaxOutputDocSizeBytes: 104857600,     internalLookupStageIntermediateDocumentMaxSizeBytes: 104857600,     internalDocumentSourceGroupMaxMemoryBytes: 104857600,     internalQueryMaxBlockingSortMemoryUsageBytes: 104857600,     internalQueryProhibitBlockingMergeOnMongoS: 0,     internalQueryMaxAddToSetBytes: 104857600,     internalDocumentSourceSetWindowFieldsMaxMemoryBytes: 104857600,     internalQueryFrameworkControl: 'trySbeRestricted',     internalQueryPlannerIgnoreIndexWithCollationForRegex: 1   },   command: {     aggregate: 'embedded_movies',     pipeline: [       {         '$vectorSearch': {           index: 'vector_index',           path: 'plot_embedding_voyage_3_large',           queryVector: [             -0.034731735,  0.008558298,   -0.0153717, -0.029912498,  0.011549547,             ...,             -0.006688767,  0.047527634,  0.040714234           ],           exact: true,           limit: 10         }       }     ],     cursor: {},     '$db': 'sample_mflix'   },   ok: 1,   '$clusterTime': {     clusterTime: Timestamp({ t: 1759341655, i: 1 }),     signature: {       hash: Binary.createFromBase64('/pUN/IbVV/OKyakbZcIug8HRS8M=', 0),       keyId: Long('7553982574624768005')     }   },   operationTime: Timestamp({ t: 1759341655, i: 1 }) } 
queryPlanner
The following example runs the explain method on an ANN and ENN vector search
query for the plot_embedding_voyage_3_large field with the queryPlanner
verbosity mode.
db.embedded_movies.explain("queryPlanner").aggregate([   {     "$vectorSearch": {       "index": "vector_index",       "path": "plot_embedding_voyage_3_large",       "queryVector": QUERY_EMBEDDING,       "numCandidates": 150,       "limit": 10     }   } ]) 
{   explainVersion: '1',   stages: [     {       '$vectorSearch': {         index: 'vector_index',         path: 'plot_embedding_voyage_3_large',         queryVector: 'redacted',         numCandidates: 150,         limit: 10,         explain: {           query: {             type: 'WrappedKnnQuery',             args: {               query: [                 {                   type: 'InstrumentableKnnFloatVectorQuery',                   args: {                     field: '$type:knnVector/plot_embedding_voyage_3_large',                     k: 150                   }                 },                 { type: 'DocAndScoreQuery', args: {} }               ]             }           },           metadata: {             mongotVersion: '1.54.0',             mongotHostName: '<hostname>.mongodb.net',             indexName: 'vector_index',             lucene: { totalSegments: 2, totalDocs: 3483 }           }         }       }     },     {       '$_internalSearchIdLookup': {         limit: Long('10'),         subPipeline: [           { '$match': { _id: { '$eq': '_id placeholder' } } }         ]       }     }   ],   queryShapeHash: '2E39BED257F2B59D3F8652E1A81A18B1140602C4E253DED9FE208D584EA00083',   serverInfo: {     host: '<hostname>.mongodb.net',     port: 27017,     version: '8.2.1-rc1',     gitVersion: '3312bdcf28aa65f5930005e21c2cb130f648b8c3'   },   serverParameters: {     internalQueryFacetBufferSizeBytes: 104857600,     internalQueryFacetMaxOutputDocSizeBytes: 104857600,     internalLookupStageIntermediateDocumentMaxSizeBytes: 104857600,     internalDocumentSourceGroupMaxMemoryBytes: 104857600,     internalQueryMaxBlockingSortMemoryUsageBytes: 104857600,     internalQueryProhibitBlockingMergeOnMongoS: 0,     internalQueryMaxAddToSetBytes: 104857600,     internalDocumentSourceSetWindowFieldsMaxMemoryBytes: 104857600,     internalQueryFrameworkControl: 'trySbeRestricted',     internalQueryPlannerIgnoreIndexWithCollationForRegex: 1   },   command: {     aggregate: 'embedded_movies',     pipeline: [       {         '$vectorSearch': {           index: 'vector_index',           path: 'plot_embedding_voyage_3_large',           queryVector: [             -0.034731735,  0.008558298,   -0.0153717, -0.029912498,  0.011549547,             ...,             -0.006688767,  0.047527634,  0.040714234           ],           numCandidates: 150,           limit: 10         }       }     ],     cursor: {},     '$db': 'sample_mflix'   },   ok: 1,   '$clusterTime': {     clusterTime: Timestamp({ t: 1759341765, i: 1 }),     signature: {       hash: Binary.createFromBase64('rPjwbtfbjVrbcvkkN0ct/b1UYa8=', 0),       keyId: Long('7553982574624768005')     }   },   operationTime: Timestamp({ t: 1759341765, i: 1 }) } 
db.embedded_movies.explain("queryPlanner").aggregate([   {     "$vectorSearch": {       "index": "vector_index",       "path": "plot_embedding_voyage_3_large",       "queryVector": QUERY_EMBEDDING,       "exact": true,       "limit": 10     }   } ]) 
{   explainVersion: '1',   stages: [     {       '$vectorSearch': {         index: 'vector_index',         path: 'plot_embedding_voyage_3_large',         queryVector: 'redacted',         exact: true,         limit: 10,         explain: {           query: {             type: 'ExactVectorSearchQuery',             args: {               field: '$type:knnVector/plot_embedding_voyage_3_large',               similarityFunction: 'dotProduct',               filter: {                 type: 'DefaultQuery',                 args: { queryType: 'FieldExistsQuery' }               }             }           },           metadata: {             mongotVersion: '1.54.0',             mongotHostName: '<hostname>.mongodb.net',             indexName: 'vector_index',             lucene: { totalSegments: 2, totalDocs: 3483 }           }         }       }     },     {       '$_internalSearchIdLookup': {         limit: Long('10'),         subPipeline: [           { '$match': { _id: { '$eq': '_id placeholder' } } }         ]       }     }   ],   queryShapeHash: '2E39BED257F2B59D3F8652E1A81A18B1140602C4E253DED9FE208D584EA00083',   serverInfo: {     host: '<hostname>.mongodb.net',     port: 27017,     version: '8.2.1-rc1',     gitVersion: '3312bdcf28aa65f5930005e21c2cb130f648b8c3'   },   serverParameters: {     internalQueryFacetBufferSizeBytes: 104857600,     internalQueryFacetMaxOutputDocSizeBytes: 104857600,     internalLookupStageIntermediateDocumentMaxSizeBytes: 104857600,     internalDocumentSourceGroupMaxMemoryBytes: 104857600,     internalQueryMaxBlockingSortMemoryUsageBytes: 104857600,     internalQueryProhibitBlockingMergeOnMongoS: 0,     internalQueryMaxAddToSetBytes: 104857600,     internalDocumentSourceSetWindowFieldsMaxMemoryBytes: 104857600,     internalQueryFrameworkControl: 'trySbeRestricted',     internalQueryPlannerIgnoreIndexWithCollationForRegex: 1   },   command: {     aggregate: 'embedded_movies',     pipeline: [       {         '$vectorSearch': {           index: 'vector_index',           path: 'plot_embedding_voyage_3_large',           queryVector: [             -0.034731735,  0.008558298,   -0.0153717, -0.029912498,  0.011549547,             ...,             -0.006688767,  0.047527634,  0.040714234           ],           exact: true,           limit: 10         }       }     ],     cursor: {},     '$db': 'sample_mflix'   },   ok: 1,   '$clusterTime': {     clusterTime: Timestamp({ t: 1759342075, i: 1 }),     signature: {       hash: Binary.createFromBase64('jQiwcAMEmfzFnVU/pyb29TnYu0w=', 0),       keyId: Long('7553982574624768005')     }   },   operationTime: Timestamp({ t: 1759342075, i: 1 }) } 
executionStats
The following example runs the explain method on an ANN and ENN vector search
query for the plot_embedding_voyage_3_large field with the executionStats
verbosity mode.
db.embedded_movies.explain("executionStats").aggregate([   {     "$vectorSearch": {       "index": "vector_index",       "path": "plot_embedding_voyage_3_large",       "queryVector": QUERY_EMBEDDING,       "numCandidates": 150,       "limit": 10     }   } ]) 
{   explainVersion: '1',   stages: [     {       '$vectorSearch': {         index: 'vector_index',         path: 'plot_embedding_voyage_3_large',         queryVector: 'redacted',         numCandidates: 150,         limit: 10,         explain: {           query: {             type: 'WrappedKnnQuery',             args: {               query: [                 {                   type: 'InstrumentableKnnFloatVectorQuery',                   args: {                     field: '$type:knnVector/plot_embedding_voyage_3_large',                     k: 150                   },                   stats: {                     context: { millisElapsed: 0 },                     match: { millisElapsed: 0 },                     score: { millisElapsed: 0 }                   }                 },                 {                   type: 'DocAndScoreQuery',                   args: {},                   stats: {                     context: {                       millisElapsed: 0.013013,                       invocationCounts: {                         createWeight: Long('1'),                         createScorer: Long('4')                       }                     },                     match: {                       millisElapsed: 0.459619,                       invocationCounts: { nextDoc: Long('152') }                     },                     score: {                       millisElapsed: 0.179147,                       invocationCounts: {                         score: Long('150'),                         setMinCompetitiveScore: Long('26')                       }                     }                   }                 }               ]             },             stats: {               context: {                 millisElapsed: 7.113224,                 invocationCounts: {                   vectorExecution: Long('1'),                   createWeight: Long('1'),                   createScorer: Long('4')                 }               },               match: {                 millisElapsed: 0.459619,                 invocationCounts: { nextDoc: Long('152') }               },               score: {                 millisElapsed: 0.179147,                 invocationCounts: {                   score: Long('150'),                   setMinCompetitiveScore: Long('26')                 }               }             }           },           collectors: {             allCollectorStats: {               millisElapsed: 0.868815,               invocationCounts: {                 collect: Long('150'),                 competitiveIterator: Long('2'),                 setScorer: Long('2')               }             }           },           metadata: {             mongotVersion: '1.54.0',             mongotHostName: '<hostname>.mongodb.net',             indexName: 'vector_index',             lucene: { totalSegments: 2, totalDocs: 3483 }           },           resourceUsage: {             majorFaults: Long('0'),             minorFaults: Long('0'),             userTimeMs: Long('0'),             systemTimeMs: Long('0'),             maxReportingThreads: 1,             numBatches: 1           },           luceneVectorSegmentStats: [             {               id: '_1',               executionType: 'Approximate',               docCount: 1531,               approximateStage: { millisElapsed: 2.58089 }             },             {               id: '_0',               executionType: 'Approximate',               docCount: 1952,               approximateStage: { millisElapsed: 3.483542 }             }           ]         }       },       nReturned: Long('10'),       executionTimeMillisEstimate: Long('29')     },     {       '$_internalSearchIdLookup': {         limit: Long('10'),         subPipeline: [           { '$match': { _id: { '$eq': '_id placeholder' } } }         ],         totalDocsExamined: Long('10'),         totalKeysExamined: Long('10'),         numDocsFilteredByIdLookup: Long('0')       },       nReturned: Long('10'),       executionTimeMillisEstimate: Long('30')     }   ],   queryShapeHash: '2E39BED257F2B59D3F8652E1A81A18B1140602C4E253DED9FE208D584EA00083',   serverInfo: {     host: '<hostname>.mongodb.net',     port: 27017,     version: '8.2.1-rc1',     gitVersion: '3312bdcf28aa65f5930005e21c2cb130f648b8c3'   },   serverParameters: {     internalQueryFacetBufferSizeBytes: 104857600,     internalQueryFacetMaxOutputDocSizeBytes: 104857600,     internalLookupStageIntermediateDocumentMaxSizeBytes: 104857600,     internalDocumentSourceGroupMaxMemoryBytes: 104857600,     internalQueryMaxBlockingSortMemoryUsageBytes: 104857600,     internalQueryProhibitBlockingMergeOnMongoS: 0,     internalQueryMaxAddToSetBytes: 104857600,     internalDocumentSourceSetWindowFieldsMaxMemoryBytes: 104857600,     internalQueryFrameworkControl: 'trySbeRestricted',     internalQueryPlannerIgnoreIndexWithCollationForRegex: 1   },   command: {     aggregate: 'embedded_movies',     pipeline: [       {         '$vectorSearch': {           index: 'vector_index',           path: 'plot_embedding_voyage_3_large',           queryVector: [             -0.034731735,  0.008558298,   -0.0153717, -0.029912498,  0.011549547,             ...,             -0.006688767,  0.047527634,  0.040714234           ],           numCandidates: 150,           limit: 10         }       }     ],     cursor: {},     '$db': 'sample_mflix'   },   ok: 1,   '$clusterTime': {     clusterTime: Timestamp({ t: 1759342175, i: 1 }),     signature: {       hash: Binary.createFromBase64('AZZrjVPfyyBofyQq/gzs9UBL+/Q=', 0),       keyId: Long('7553982574624768005')     }   },   operationTime: Timestamp({ t: 1759342175, i: 1 }) } 
db.embedded_movies.explain("executionStats").aggregate([   {     "$vectorSearch": {       "index": "vector_index",       "path": "plot_embedding_voyage_3_large",       "queryVector": QUERY_EMBEDDING,       "exact": true,       "limit": 10     }   } ]) 
{   explainVersion: '1',   stages: [     {       '$vectorSearch': {         index: 'vector_index',         path: 'plot_embedding_voyage_3_large',         queryVector: 'redacted',         exact: true,         limit: 10,         explain: {           query: {             type: 'ExactVectorSearchQuery',             args: {               field: '$type:knnVector/plot_embedding_voyage_3_large',               similarityFunction: 'dotProduct',               filter: {                 type: 'DefaultQuery',                 args: { queryType: 'FieldExistsQuery' },                 stats: {                   context: {                     millisElapsed: 0.037129,                     invocationCounts: {                       createWeight: Long('1'),                       createScorer: Long('4')                     }                   },                   match: {                     millisElapsed: 1.128957,                     invocationCounts: { nextDoc: Long('3405') }                   },                   score: { millisElapsed: 0 }                 }               }             },             stats: {               context: {                 millisElapsed: 0.061268,                 invocationCounts: { createWeight: Long('1'), createScorer: Long('4') }               },               match: {                 millisElapsed: 2.531393,                 invocationCounts: { nextDoc: Long('3405') }               },               score: {                 millisElapsed: 7.956341,                 invocationCounts: {                   score: Long('3403'),                   setMinCompetitiveScore: Long('63')                 }               }             }           },           collectors: {             allCollectorStats: {               millisElapsed: 10.004281,               invocationCounts: {                 collect: Long('3403'),                 competitiveIterator: Long('2'),                 setScorer: Long('2')               }             }           },           metadata: {             mongotVersion: '1.54.0',             mongotHostName: '<hostname>.mongodb.net',             indexName: 'vector_index',             lucene: { totalSegments: 2, totalDocs: 3483 }           },           resourceUsage: {             majorFaults: Long('0'),             minorFaults: Long('0'),             userTimeMs: Long('0'),             systemTimeMs: Long('0'),             maxReportingThreads: 1,             numBatches: 1           }         }       },       nReturned: Long('10'),       executionTimeMillisEstimate: Long('25')     },     {       '$_internalSearchIdLookup': {         limit: Long('10'),         subPipeline: [           { '$match': { _id: { '$eq': '_id placeholder' } } }         ],         totalDocsExamined: Long('10'),         totalKeysExamined: Long('10'),         numDocsFilteredByIdLookup: Long('0')       },       nReturned: Long('10'),       executionTimeMillisEstimate: Long('26')     }   ],   queryShapeHash: '2E39BED257F2B59D3F8652E1A81A18B1140602C4E253DED9FE208D584EA00083',   serverInfo: {     host: '<hostname>.mongodb.net',     port: 27017,     version: '8.2.1-rc1',     gitVersion: '3312bdcf28aa65f5930005e21c2cb130f648b8c3'   },   serverParameters: {     internalQueryFacetBufferSizeBytes: 104857600,     internalQueryFacetMaxOutputDocSizeBytes: 104857600,     internalLookupStageIntermediateDocumentMaxSizeBytes: 104857600,     internalDocumentSourceGroupMaxMemoryBytes: 104857600,     internalQueryMaxBlockingSortMemoryUsageBytes: 104857600,     internalQueryProhibitBlockingMergeOnMongoS: 0,     internalQueryMaxAddToSetBytes: 104857600,     internalDocumentSourceSetWindowFieldsMaxMemoryBytes: 104857600,     internalQueryFrameworkControl: 'trySbeRestricted',     internalQueryPlannerIgnoreIndexWithCollationForRegex: 1   },   command: {     aggregate: 'embedded_movies',     pipeline: [       {         '$vectorSearch': {           index: 'vector_index',           path: 'plot_embedding_voyage_3_large',           queryVector: [             -0.034731735,  0.008558298,   -0.0153717, -0.029912498,  0.011549547,             ...,             -0.006688767,  0.047527634,  0.040714234           ],           exact: true,           limit: 10         }       }     ],     cursor: {},     '$db': 'sample_mflix'   },   ok: 1,   '$clusterTime': {     clusterTime: Timestamp({ t: 1759342255, i: 1 }),     signature: {       hash: Binary.createFromBase64('sHuAxj9o8MbGe4iRz0Pv1PSi+UY=', 0),       keyId: Long('7553982574624768005')     }   },   operationTime: Timestamp({ t: 1759342255, i: 1 }) } 
db.embedded_movies.explain("executionStats").aggregate([   {     "$vectorSearch": {       "index": "vector_index",       "path": "plot_embedding_voyage_3_large",       "queryVector": QUERY_EMBEDDING,       "numCandidates": 150,       "limit": 10,       "explainOptions": {         "traceDocumentIds": [           ObjectId('573a13d8f29313caabda6557'), ObjectId('573a1398f29313caabce98d9'), ObjectId('573a1391f29313caabcd8319'), ObjectId('573a1398f29313caabceb500'), ObjectId('573a1397f29313caabce780e')         ]       }     }   } ]) 
{   explainVersion: '1',   stages: [     {       '$vectorSearch': {         index: 'vector_index',         path: 'plot_embedding_voyage_3_large',         queryVector: 'redacted',         numCandidates: 150,         limit: 10,         explainOptions: {           traceDocumentIds: [             ObjectId('573a13d8f29313caabda6557'),             ObjectId('573a1398f29313caabce98d9'),             ObjectId('573a1391f29313caabcd8319'),             ObjectId('573a1398f29313caabceb500'),             ObjectId('573a1397f29313caabce780e')           ]         },         explain: {           query: {             type: 'WrappedKnnQuery',             args: {               query: [                 {                   type: 'InstrumentableKnnFloatVectorQuery',                   args: {                     field: '$type:knnVector/plot_embedding_voyage_3_large',                     k: 150                   },                   stats: {                     context: { millisElapsed: 0 },                     match: { millisElapsed: 0 },                     score: { millisElapsed: 0 }                   }                 },                 {                   type: 'DocAndScoreQuery',                   args: {},                   stats: {                     context: {                       millisElapsed: 0.010987,                       invocationCounts: {                         createWeight: Long('1'),                         createScorer: Long('4')                       }                     },                     match: {                       millisElapsed: 0.009977,                       invocationCounts: { nextDoc: Long('152') }                     },                     score: {                       millisElapsed: 0.018875,                       invocationCounts: {                         score: Long('150'),                         setMinCompetitiveScore: Long('26')                       }                     }                   }                 }               ]             },             stats: {               context: {                 millisElapsed: 7.55246,                 invocationCounts: {                   vectorExecution: Long('1'),                   createWeight: Long('1'),                   createScorer: Long('4')                 }               },               match: {                 millisElapsed: 0.009977,                 invocationCounts: { nextDoc: Long('152') }               },               score: {                 millisElapsed: 0.018875,                 invocationCounts: {                   score: Long('150'),                   setMinCompetitiveScore: Long('26')                 }               }             }           },           collectors: {             allCollectorStats: {               millisElapsed: 0.148807,               invocationCounts: {                 collect: Long('150'),                 competitiveIterator: Long('2'),                 setScorer: Long('2')               }             }           },           metadata: {             mongotVersion: '1.54.0',             mongotHostName: '<hostname>.mongodb.net',             indexName: 'vector_index',             lucene: { totalSegments: 2, totalDocs: 3483 }           },           resourceUsage: {             majorFaults: Long('0'),             minorFaults: Long('0'),             userTimeMs: Long('0'),             systemTimeMs: Long('0'),             maxReportingThreads: 1,             numBatches: 1           },           vectorTracing: [             {               documentId: ObjectId('573a1391f29313caabcd8319'),               visited: false,               luceneSegment: '_0'             },             {               documentId: ObjectId('573a1397f29313caabce780e'),               visited: true,               vectorSearchScore: 0.7469133734703064,               luceneSegment: '_0'             },             {               documentId: ObjectId('573a1398f29313caabce98d9'),               visited: false,               luceneSegment: '_0'             },             {               documentId: ObjectId('573a1398f29313caabceb500'),               visited: true,               vectorSearchScore: 0.7521393895149231,               luceneSegment: '_0'             },             {               documentId: ObjectId('573a13d8f29313caabda6557'),               visited: true,               vectorSearchScore: 0.7710106372833252,               luceneSegment: '_1'             }           ],           luceneVectorSegmentStats: [             {               id: '_1',               executionType: 'Approximate',               docCount: 1531,               approximateStage: { millisElapsed: 2.73042 }             },             {               id: '_0',               executionType: 'Approximate',               docCount: 1952,               approximateStage: { millisElapsed: 4.136979 }             }           ]         }       },       nReturned: Long('10'),       executionTimeMillisEstimate: Long('21')     },     {       '$_internalSearchIdLookup': {         limit: Long('10'),         subPipeline: [           { '$match': { _id: { '$eq': '_id placeholder' } } }         ],         totalDocsExamined: Long('10'),         totalKeysExamined: Long('10'),         numDocsFilteredByIdLookup: Long('0')       },       nReturned: Long('10'),       executionTimeMillisEstimate: Long('22')     }   ],   queryShapeHash: '2E39BED257F2B59D3F8652E1A81A18B1140602C4E253DED9FE208D584EA00083',   serverInfo: {     host: '<hostname>.mongodb.net',     port: 27017,     version: '8.2.1-rc1',     gitVersion: '3312bdcf28aa65f5930005e21c2cb130f648b8c3'   },   serverParameters: {     internalQueryFacetBufferSizeBytes: 104857600,     internalQueryFacetMaxOutputDocSizeBytes: 104857600,     internalLookupStageIntermediateDocumentMaxSizeBytes: 104857600,     internalDocumentSourceGroupMaxMemoryBytes: 104857600,     internalQueryMaxBlockingSortMemoryUsageBytes: 104857600,     internalQueryProhibitBlockingMergeOnMongoS: 0,     internalQueryMaxAddToSetBytes: 104857600,     internalDocumentSourceSetWindowFieldsMaxMemoryBytes: 104857600,     internalQueryFrameworkControl: 'trySbeRestricted',     internalQueryPlannerIgnoreIndexWithCollationForRegex: 1   },   command: {     aggregate: 'embedded_movies',     pipeline: [       {         '$vectorSearch': {           index: 'vector_index',           path: 'plot_embedding_voyage_3_large',           queryVector: [             -0.034731735,  0.008558298,   -0.0153717, -0.029912498,  0.011549547,             ...,             -0.006688767,  0.047527634,  0.040714234           ],           numCandidates: 150,           limit: 10,           explainOptions: {             traceDocumentIds: [               ObjectId('573a13d8f29313caabda6557'),               ObjectId('573a1398f29313caabce98d9'),               ObjectId('573a1391f29313caabcd8319'),               ObjectId('573a1398f29313caabceb500'),               ObjectId('573a1397f29313caabce780e')             ]           }         }       }     ],     cursor: {},     '$db': 'sample_mflix'   },   ok: 1,   '$clusterTime': {     clusterTime: Timestamp({ t: 1759343038, i: 1 }),     signature: {       hash: Binary.createFromBase64('E3FSIwLHavtFVMsmuqJM5reQc4I=', 0),       keyId: Long('7553982574624768005')     }   },   operationTime: Timestamp({ t: 1759343038, i: 1 }) }