mirror of
https://github.com/Tencent/WeKnora.git
synced 2026-09-01 14:53:07 +08:00
492e92580b
Closes #620 #497. Add opt-in Langfuse observability covering all five model types (chat, embedding, rerank, VLM, ASR) with HTTP-request-scoped traces and Docker Compose support (both cloud and self-hosted). Core package internal/tracing/langfuse: - HTTP client with batched async ingestion (non-blocking in request path) - Sampling, environment / release tagging, and graceful fallback when LANGFUSE_* env vars are absent (wrappers become no-ops) - Gin middleware opens one trace per traced request and finishes it after the handler chain returns, attaching method / path / user / session - Trace context is stored under a typed key exported from internal/types so logger.CloneContext can preserve it across handler / goroutine boundaries (otherwise each LLM call auto-created an orphan trace, fragmenting one request into many) Per-model generation wrappers (opt-in via NewChat/NewEmbedder/...): - chat: captures prompt, streaming output, token usage + TTFT - embedding: approximates tokens when the provider omits usage - rerank: previews query/docs, summarizes results to keep payload small - vlm: records image count and total bytes, never uploads raw pixels - asr: records file size and audio duration, never uploads audio bytes Async title generation (GenerateTitleAsync) now forwards the trace key into the goroutine so title calls appear under the parent chat trace. Docker Compose: - LANGFUSE_* env passthrough on the `app` service for cloud deployments - Optional `langfuse` profile spins up a self-hosted Langfuse stack that reuses WeKnora's existing PostgreSQL (separate database via an idempotent init container that fixes ICU collation drift) and Redis (separate DB number), adding only ClickHouse, MinIO, web and worker containers - web/worker entrypoints URL-encode DB_PASSWORD / REDIS_PASSWORD at start to avoid Prisma P1013 when passwords contain @ / # / etc. Docs: docs/Langfuse集成.md covers cloud vs self-hosted, per-model usage strategy, code map, and resource footprint.
61 lines
1.7 KiB
Bash
61 lines
1.7 KiB
Bash
# WeKnora Lite 配置模板
|
||
# 复制此文件为 .env.lite 并按需修改
|
||
# cp .env.lite.example .env.lite
|
||
|
||
GIN_MODE=debug
|
||
|
||
# 日志级别,可选值:debug, info, warn, error, fatal
|
||
LOG_LEVEL=debug
|
||
|
||
# 可选:日志文件绝对路径;未配置时,macOS .app 默认写入
|
||
# ~/Library/Logs/WeKnora Lite/WeKnora Lite.log
|
||
# LOG_PATH=/absolute/path/to/weknora-lite.log
|
||
|
||
# === 数据库 ===
|
||
# macOS .app 中相对路径会自动重定向到
|
||
# ~/Library/Application Support/WeKnora Lite/data/
|
||
DB_DRIVER=sqlite
|
||
DB_PATH=./data/weknora.db
|
||
|
||
# === 检索引擎(FTS5 + sqlite-vec)===
|
||
RETRIEVE_DRIVER=sqlite
|
||
|
||
# === 文件存储 ===
|
||
STORAGE_TYPE=local
|
||
LOCAL_STORAGE_BASE_DIR=./data/files
|
||
|
||
# === 流管理(内存,无 Redis)===
|
||
STREAM_MANAGER_TYPE=memory
|
||
|
||
# === LLM 服务 ===
|
||
# Ollama 本地服务(默认地址,按需修改)
|
||
OLLAMA_BASE_URL=http://127.0.0.1:11434
|
||
# 如使用其他 OpenAI 兼容服务,取消注释:
|
||
# OPENAI_API_KEY=sk-xxx
|
||
# OPENAI_BASE_URL=https://api.openai.com/v1
|
||
|
||
# === 安全配置(生产环境请务必修改!)===
|
||
TENANT_AES_KEY=CHANGE-ME-32-char-secret-key!!!!
|
||
JWT_SECRET=CHANGE-ME-jwt-secret
|
||
|
||
# === 功能开关 ===
|
||
NEO4J_ENABLE=false
|
||
WEKNORA_SANDBOX_MODE=disabled
|
||
ENABLE_GRAPH_RAG=false
|
||
DISABLE_REGISTRATION=false
|
||
|
||
# === Langfuse 可观测性(可选) ===
|
||
# 追踪 chat / embedding / rerank / VLM / ASR 的 prompt、响应与 token 消耗。
|
||
# 同时填了 PUBLIC_KEY 和 SECRET_KEY 就会自动启用,详见 docs/Langfuse集成.md。
|
||
# LANGFUSE_PUBLIC_KEY=pk-lf-xxxxxxxx
|
||
# LANGFUSE_SECRET_KEY=sk-lf-xxxxxxxx
|
||
# LANGFUSE_HOST=https://cloud.langfuse.com
|
||
|
||
# === 性能 ===
|
||
CONCURRENCY_POOL_SIZE=3
|
||
|
||
# Docreader 地址
|
||
DOCREADER_ADDR=127.0.0.1:50051
|
||
|
||
# Docreader 传输方式
|
||
DOCREADER_TRANSPORT=grpc |