Overview
TheFlatIndexParam class configures a flat (brute-force) index. A flat index performs exact nearest neighbor search by comparing the query vector against all vectors in the collection. It provides perfect accuracy with a simple implementation, making it ideal for small datasets or as a baseline for accuracy comparison.
Constructor
Parameters
Distance metric used for similarity computation. Options:
MetricType.IP- Inner product (default)MetricType.L2- Euclidean distanceMetricType.COSINE- Cosine similarity
Optional quantization type for vector compression. Options:
QuantizeType.UNDEFINED- No quantization (default, perfect accuracy)QuantizeType.FP16- 16-bit floating point (slight accuracy trade-off)QuantizeType.INT8- 8-bit integer quantization (more accuracy trade-off)
Methods
to_dict()
Convert the index parameters to a dictionary representation. Returns:dict - Dictionary with all index parameter fields.
Examples
Basic flat index
Memory-efficient flat index
Euclidean distance search
Using with a collection
Baseline accuracy testing
Performance Characteristics
Time Complexity
- Search time: O(n * d)
- n = number of vectors in collection
- d = dimension of vectors
- Index build time: O(1) - no index structure to build
- Insert time: O(1) - simple append operation
Space Complexity
- Memory: dimension * bytes_per_element * number_of_vectors
- FLOAT32: 4 bytes per element
- FP16: 2 bytes per element
- INT8: 1 byte per element
When to Use Flat Index
Flat index is ideal for:
- Small datasets (under 10,000 vectors)
- Scenarios requiring perfect 100% accuracy
- Baseline accuracy testing for other index types
- Low-dimensional vectors (under 50 dimensions)
- Development and debugging
- When simplicity is more important than speed
Comparison with Other Index Types
| Feature | Flat | HNSW | IVF |
|---|---|---|---|
| Accuracy | 100% | 95-99% | 85-95% |
| Speed (large dataset) | Slow | Fast | Fast |
| Memory | Low | High | Medium |
| Build time | Instant | Slow | Medium |
| Best for | Small data | High accuracy | Large data |
Use Cases
1. Baseline Testing
Use flat index to establish ground truth accuracy for comparing approximate indexes:2. Small Dataset Search
For datasets with fewer than 10,000 vectors, flat index provides simple and fast enough search:3. Exact KNN for Verification
When you need to verify or audit search results:4. Development and Prototyping
Start with flat index during development, then switch to HNSW or IVF for production:Quantization Trade-offs
Using quantization with flat index:
FP16: ~50% memory reduction, minimal accuracy lossINT8: ~75% memory reduction, small accuracy loss- Without quantization: Perfect accuracy, full memory usage
Migration Path
As your dataset grows, consider migrating to approximate indexes:See Also
- HnswIndexParam - Graph-based approximate index
- IVFIndexParam - Cluster-based approximate index
- VectorQuery - Querying with flat indexes