Configuration
@nx/searchđọc env từ process host (commerce). Nó định nghĩa key riêng (src/common/environments.ts) trên nền các Kafka key của@nx/core, cộng config embedding + pipeline backed bởi DB trong bảngConfiguration.
1. Biến môi trường
Riêng cho search (EnvironmentKeys mở rộng core)
| Tên | Kiểu | Mặc định | Bắt buộc | Mô tả |
|---|---|---|---|---|
APP_ENV_TYPESENSE_NODES | string (CSV) | http:localhost:8108 | Nodes dạng protocol:host:port, phân tách bằng dấu phẩy. Không phải URL | |
APP_ENV_TYPESENSE_API_KEY | string | xyz | Typesense API key | |
APP_ENV_CDC_DLQ_TOPIC | string | nx.seller.cdc.dlq | Dead-letter topic cho message CDC fail | |
APP_ENV_CDC_CIRCUIT_BREAKER_ENABLED | boolean (string) | false | Bật Typesense health probe + pause consumer |
Kafka / CDC consumer (kế thừa từ @nx/core)
| Tên | Kiểu | Mặc định | Mô tả |
|---|---|---|---|
APP_ENV_KAFKA_BROKERS | string (CSV) | localhost:19092 | Bootstrap brokers |
APP_ENV_KAFKA_CLIENT_ID | string | commerce-cdc-consumer | Client id CDC consumer |
APP_ENV_KAFKA_GROUP_ID | string | commerce-cdc-group | Consumer group CDC |
APP_ENV_KAFKA_SASL_ENABLE | boolean (string) | false | Bật SASL |
APP_ENV_KAFKA_SASL_MECHANISM | string | SCRAM-SHA-512 | SASL mechanism (khi bật) |
APP_ENV_KAFKA_SASL_USERNAME | string | — | SASL user (khi bật) |
APP_ENV_KAFKA_SASL_PASSWORD | string | — | SASL password (khi bật) |
Các mặc định
commerce-cdc-*phản ánh host hiện tại; chúng không hard-code cho một service "search".
2. Feature Flags
| Flag | Mặc định | Mô tả |
|---|---|---|
APP_ENV_CDC_CIRCUIT_BREAKER_ENABLED | false | Gate CDC circuit breaker (health probe + pause) |
ISearchParams.disableSemanticSearch | false (theo từng query) | Bỏ trường embedding khỏi query_by → keyword nghiêm ngặt |
Auto-embedding (embed.from) | off trừ khi có config DB | Bật chỉ khi có config model embedding + collection có embeddingField/embeddingFields |
3. Dữ liệu Seed
Không có PostgreSQL migration riêng. "Seeding" qua các script developer feed/backfill dữ liệu:
| Script | Command | Action | Idempotent |
|---|---|---|---|
scripts/data-feeder/index.ts | bun run feed-data[:small|medium|large] | Tạo dữ liệu giả, POST qua Commerce API (cần JWT) | no (tạo dòng) |
scripts/migrate-add-references.ts | bun run migrate:references[:dry] | Backfill trường relation/reference trong Typesense | yes |
scripts/migrate-add-denorm-fields.ts | bun run migrate:denorm[:dry] | Backfill trường denormalized trong Typesense | yes |
4. Lưu trữ Configuration (bảng Configuration)
Đọc bởi SearchConfigurationService khi bootstrap; fallback về DEFAULT_SEARCH_PIPELINE_CONFIG.
| Configuration kind | Read by | Binds | Notes |
|---|---|---|---|
TYPESENSE_EMBEDDING_CONFIG (SystemConfigurations) | ApplicationEmbeddingConfigurationComponent | EMBEDDING_MODEL_CONFIG | Tùy chọn; vắng → search chỉ keyword |
| Config pipeline search | ApplicationEmbeddingConfigurationComponent | SEARCH_PIPELINE_CONFIG | Override partial merge lên defaults |
Mặc định config pipeline (DEFAULT_SEARCH_PIPELINE_CONFIG)
| Group | Field | Mặc định |
|---|---|---|
cdc.kafkaConsumer | maxWaitTimeMs / maxBytes | 500 / 5 MB |
cdc.batching | maxBatchSize / flushIntervalMs | 200 / 2000 |
cdc.processing | typesenseBatchSize | 100 |
circuitBreaker | probeIntervalMs | 30 000 |
circuitBreaker | quietWindowMsTypesense / quietWindowMsGoogle | 30 000 / 90 000 |
circuitBreaker | maxOpenMs | 1 800 000 (30 phút) |
lsnLookup | pageSize | 250 |
search | cacheTtlSeconds | 5 |
search | paginationDefaultLimit / paginationMaxLimit | 10 / 250 |