配置 SSOT(TOML + .env) 统一错误契约 Auth 与事务边界 Redis / Celery 可靠性:业务 Redis(DB/0)与 Celery broker/backend(DB/1)显式拆分;连接池、sync client 可观测性(OpenTelemetry + LGTM)
2.2 KiB
2.2 KiB
title, impact, impactDescription, tags, description, alwaysApply
| title | impact | impactDescription | tags | description | alwaysApply |
|---|---|---|---|---|---|
| Configure Vector Indexes Properly | HIGH | Correct configuration is essential for vector search accuracy | vector, index, hnsw, flat, embeddings, rqe | Configure Vector Indexes Properly | true |
Configure Vector Indexes Properly
Set the correct dimensions, algorithm, and distance metric for your embeddings. Vector indexes can be created via CLI, Redis Insight, or any client library.
Correct: Create index via Redis CLI or Insight.
FT.CREATE idx:docs ON HASH PREFIX 1 doc:
SCHEMA
content TEXT
embedding VECTOR HNSW 6
TYPE FLOAT32
DIM 1536
DISTANCE_METRIC COSINE
Correct: Create index via Python (redis-py).
from redis import Redis
from redis.commands.search.field import TextField, VectorField
from redis.commands.search.index_definition import IndexDefinition
r = Redis()
# Define schema with vector field
schema = [
TextField("content"),
VectorField(
"embedding",
algorithm="HNSW",
attributes={
"TYPE": "FLOAT32",
"DIM": 1536, # Must match your embedding model
"DISTANCE_METRIC": "COSINE"
}
)
]
r.ft("idx:docs").create_index(schema, definition=IndexDefinition(prefix=["doc:"]))
Correct: Create index via RedisVL.
from redisvl.index import SearchIndex
from redisvl.schema import IndexSchema
schema = IndexSchema.from_dict({
"index": {"name": "idx:docs", "prefix": "doc:"},
"fields": [
{"name": "content", "type": "text"},
{"name": "embedding", "type": "vector", "attrs": {
"dims": 1536,
"algorithm": "HNSW",
"datatype": "FLOAT32",
"distance_metric": "COSINE"
}}
]
})
index = SearchIndex(schema)
index.create(overwrite=True)
Incorrect: Mismatched dimensions or wrong distance metric.
# Bad: Wrong dimensions for your model
{"dims": 768} # But your selected embedding model outputs a different size
# Bad: Wrong metric for normalized embeddings
{"distance_metric": "L2"} # When embeddings are normalized for COSINE
Reference: Redis Vector Search