Search_time vs Indexing_time Approximate kNN Modes in Amazon OpenSearch Service: Key Differences Explained

Search-time (ef_search) controls query traversal depth for latency versus recall trade-offs, while indexing-time (ef_construction) determines graph density during vector ingestion, affecting build speed and ultimate search quality.

Amazon OpenSearch Service implements approximate k-Nearest-Neighbor (kNN) search using the HNSW (Hierarchical Navigable Small World) algorithm. When building semantic search applications using the aws-samples/sample-for-amazon-opensearch-service-tutorials-101 repository, you must configure two distinct parameter sets that control search_time and indexing_time approximate kNN modes. These parameters operate at different phases of the vector lifecycle—one during index construction and one during query execution.

What Is Search-Time Approximate kNN Mode?

Search-time approximation determines how exhaustively the HNSW graph is traversed when executing a kNN query. This mode directly impacts the trade-off between query latency and result accuracy (recall).

In the tutorial repository, the search-time parameter is configured in artifacts/index_lambda/opensearch_index.py at lines 259-261:

"knn.algo_param.ef_search": 100

The ef_search parameter specifies the size of the dynamic candidate list used during graph traversal. Higher values force the algorithm to examine more nodes, increasing the probability of finding the true nearest neighbors at the cost of slower query performance. Lower values reduce latency but may return suboptimal results.

What Is Indexing-Time Approximate kNN Mode?

Indexing-time approximation controls how the HNSW graph is constructed when vectors are first ingested into the index. This mode affects the density and connectivity of the graph structure that is persisted to storage.

The tutorial configures the indexing-time parameter in artifacts/index_lambda/opensearch_index.py at lines 303-304:

"ef_construction": 128,

This parameter appears within the method.parameters block of the kNN vector field mapping (lines 298-306):

"method": {
    "name":"hnsw",
    "engine":"faiss",
    "space_type": "innerproduct",
    "parameters": {
        "ef_construction": 128,
        "m": 24
    }
}

Higher ef_construction values build a more connected, denser graph that typically yields better search recall, but they significantly slow down bulk indexing operations and increase memory consumption during ingestion. Lower values enable faster data loading but may produce a sparser graph that reduces search accuracy.

Key Differences Between Search-Time and Indexing-Time Parameters

Understanding the distinction between these two modes is critical for optimizing vector search workloads.

Aspect Search-Time (ef_search) Indexing-Time (ef_construction)
Lifecycle Phase Query execution Index construction/ingestion
Primary Effect Controls traversal depth during search Controls graph density during build
Performance Impact Affects query latency and recall Affects indexing throughput and memory
Configuration Location Index settings block Field mapping method.parameters
Storage Impact None (runtime only) Affects index size, especially in on-disk mode

Configuration Examples from the OpenSearch Tutorial Repository

The tutorial repository demonstrates both modes working together in artifacts/index_lambda/opensearch_index.py. The implementation uses the FAISS engine with HNSW for both on-disk and in-memory vector indexes.

For the on-disk vector configuration (lines 294-298):

"mode": "on_disk",

This mode stores vectors on EBS rather than in RAM, but both ef_search and ef_construction apply identically regardless of the storage mode. The search-time parameter is set globally for the index:

settings = {
    "index.knn": True,
    "knn.algo_param.ef_search": 100
}

While the indexing-time parameter is field-specific:

"embedding": {
    "type": "knn_vector",
    "dimension": 1536,
    "method": {
        "name": "hnsw",
        "engine": "faiss",
        "space_type": "innerproduct",
        "parameters": {
            "ef_construction": 128,
            "m": 24
        }
    }
}

Performance Trade-offs and Tuning Recommendations

Balancing ef_search and ef_construction requires understanding your workload priorities.

For Search-Heavy Workloads:

Increase ef_search (e.g., 200-800) when query accuracy is critical and latency requirements are relaxed. Monitor query latency metrics to ensure the traversal depth does not exceed service level objectives.

For Ingestion-Heavy Workloads:

Reduce ef_construction (e.g., 64-100) to accelerate bulk indexing operations. This is particularly important during initial data loads or when processing high-velocity vector streams.

For Balanced Workloads:

The tutorial's default values (ef_search: 100, ef_construction: 128) provide a reasonable starting point for general semantic search applications using the FAISS engine with inner product space type.

Summary

  • Search-time mode (ef_search) controls HNSW graph traversal depth during query execution, directly impacting latency versus recall trade-offs.
  • Indexing-time mode (ef_construction) determines graph density during vector ingestion, affecting build speed, memory usage, and eventual search quality.
  • The tutorial repository configures ef_search in index settings (artifacts/index_lambda/opensearch_index.py lines 259-261) and ef_construction in field mappings (lines 303-304).
  • Both parameters use the FAISS HNSW implementation and apply regardless of whether vectors are stored in-memory or on-disk.

Frequently Asked Questions

What happens if I set ef_search too high?

Setting ef_search too high causes excessive graph traversal during queries, significantly increasing latency without proportional gains in recall once the value exceeds the number of nearest neighbors requested. For most applications, values between 100 and 200 provide sufficient accuracy, while values above 500 should be reserved for applications requiring extremely high recall where query speed is secondary.

Does ef_construction affect existing documents in an index?

No, ef_construction only affects how the HNSW graph is built when documents are first indexed. Changing this parameter requires reindexing existing data to rebuild the graph with the new construction settings. The parameter has no effect on search-time behavior for documents that were already indexed under different construction parameters.

Can I use different ef_search values for different queries on the same index?

Yes, you can dynamically override ef_search at query time using the knn parameter in the search request body. While the index settings define a default value (100 in the tutorial), individual queries can specify different ef_search values to balance accuracy and latency for specific use cases. This allows high-precision searches for critical queries while maintaining faster defaults for general browsing.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →