HNSW Index Insufficient Results Error
warningWhen the HNSW index cannot return the requested number of results, queries fail with a 2D array error. This happens when M, ef_construction, or ef_search parameters are too small for the dataset structure, limiting the index's ability to traverse and find sufficient neighbors.
Query operations fail with error 'Cannot return the results in a contiguous 2D array'. The number of results returned is consistently less than the requested n_results parameter, indicating index parameter misconfiguration.
1. Investigate: Check error logs for '2D array' error patterns. Compare n_results requested vs actual results returned across queries. Review HNSW configuration parameters (M, ef_construction, ef_search). 2. Diagnose: Calculate expected graph connectivity: M determines max connections per node. Low M in sparse datasets limits traversal paths. Check collection size vs n_results — very small collections naturally have this issue. 3. Remediate (immediate): Reduce n_results parameter in queries to match actual available neighbors. Set n_results <= collection_size / 10 as a safe threshold. 4. Remediate (long-term): Increase HNSW M parameter (default 16, try 32-64) to improve connectivity. Increase ef_construction (default 100, try 200-400) for better index quality. Increase ef_search (default 10, try 50-100) for more thorough search. Rebuild index after parameter changes. 5. Prevent: Set n_results based on collection size: for collections < 1000, limit to collection_size / 5. Document HNSW parameter recommendations for different use cases.