配置 SSOT(TOML + .env) 统一错误契约 Auth 与事务边界 Redis / Celery 可靠性:业务 Redis(DB/0)与 Celery broker/backend(DB/1)显式拆分;连接池、sync client 可观测性(OpenTelemetry + LGTM)
2.1 KiB
2.1 KiB
title, impact, impactDescription, tags, description, alwaysApply
| title | impact | impactDescription | tags | description | alwaysApply |
|---|---|---|---|---|---|
| Choose HNSW vs FLAT Based on Requirements | HIGH | HNSW trades accuracy for speed, FLAT provides exact results | vector, hnsw, flat, algorithm, performance | Choose HNSW vs FLAT Based on Requirements | true |
Choose HNSW vs FLAT Based on Requirements
Select the right algorithm based on your accuracy requirements and dataset size.
| Algorithm | Speed | Accuracy | Memory | Best For |
|---|---|---|---|---|
| HNSW | Fast (approximate) | ~95%+ recall tunable | Higher | Large datasets (>10k vectors) |
| FLAT | Slower (exact) | 100% (exact) | Lower | Small datasets, accuracy-critical |
Correct: Use HNSW for large-scale production workloads.
from redisvl.schema import IndexSchema
# HNSW - fast approximate search, tunable accuracy
schema = IndexSchema.from_dict({
"index": {"name": "idx:docs", "prefix": "doc:"},
"fields": [
{"name": "embedding", "type": "vector", "attrs": {
"dims": 1536,
"algorithm": "HNSW",
"distance_metric": "COSINE",
"datatype": "FLOAT32",
"m": 16, # Higher = more accurate, more memory
"ef_construction": 200 # Higher = better index quality, slower build
}}
]
})
Correct: Use FLAT when exact results are required.
# FLAT - exact brute-force search, guaranteed accuracy
schema = IndexSchema.from_dict({
"index": {"name": "idx:small", "prefix": "small:"},
"fields": [
{"name": "embedding", "type": "vector", "attrs": {
"dims": 1536,
"algorithm": "FLAT",
"distance_metric": "COSINE"
}}
]
})
Tuning HNSW accuracy vs speed:
M: Connections per node (16-64). Higher = better recall, more memoryEF_CONSTRUCTION: Build-time parameter (100-500). Higher = better graph qualityEF_RUNTIME: Query-time parameter. Higher = better recall, slower queries
Reference: Redis Vector Search