faiss server
This commit is contained in:
34
faiss/config.py
Normal file
34
faiss/config.py
Normal file
@@ -0,0 +1,34 @@
|
||||
# config.py
|
||||
from pydantic_settings import BaseSettings
|
||||
from functools import lru_cache
|
||||
|
||||
class Settings(BaseSettings):
|
||||
# FAISS 配置(已优化为你的 LLM 相似问题缓存场景)
|
||||
FAISS_DIM: int = 1024 # 根据你的 embedding 模型修改(e.g. bge-large=1024, text-embedding-3-large=3072)
|
||||
FAISS_INDEX_PATH: str = "faiss_index.bin"
|
||||
FAISS_INDEX_TYPE: str = "HNSW" # 默认改为 HNSW(最推荐)
|
||||
|
||||
# HNSW 专用参数(速度 + 精度平衡)
|
||||
HNSW_M: int = 32 # 每层连接数(16-64),越大精度越高但内存稍多
|
||||
HNSW_EF_CONSTRUCTION: int = 200 # 构建质量(100-400)
|
||||
HNSW_EF_SEARCH: int = 64 # 查询精度(32-128),越大越准但稍慢
|
||||
|
||||
# 是否使用余弦相似度(强烈推荐用于文本 embedding)
|
||||
USE_COSINE_SIMILARITY: bool = True # True = 自动归一化 + Index*IP
|
||||
ENABLE_REQUEST_LOGS: bool = True # 是否打印插入/搜索业务日志
|
||||
|
||||
# FastAPI 配置
|
||||
APP_HOST: str = "0.0.0.0"
|
||||
APP_PORT: int = 8000
|
||||
APP_TITLE: str = "FAISS 相似问题缓存服务"
|
||||
APP_DESCRIPTION: str = "LLM 对话语义缓存 - 减少 token 消耗"
|
||||
|
||||
class Config:
|
||||
env_file = ".env"
|
||||
env_file_encoding = "utf-8"
|
||||
extra = "ignore"
|
||||
|
||||
|
||||
@lru_cache()
|
||||
def get_settings() -> Settings:
|
||||
return Settings()
|
||||
Reference in New Issue
Block a user