Enhance impact analysis and configuration for vector persistence and API integration. Update main.spec to clarify data handling for ChromaDB, ensuring vector directories are excluded from packaging. Modify Text2SQLOrchestrator to unify question normalization for consistent SQL generation across languages. Introduce SchemaIndexer improvements for persistent vector storage and optimize embedding retrieval processes. Update documentation and comments for clarity on configuration changes and behavior adjustments.
This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -1,8 +1,9 @@
|
||||
"""
|
||||
Few-shot 经验样本的 Chroma 向量库存储与检索。
|
||||
|
||||
与 SchemaIndexer 一致:使用项目统一 ``get_embedder()``;默认 Chroma 为内存
|
||||
(``EphemeralClient``)。离线灌库脚本可设 ``persist_to_disk=True`` 写入磁盘。
|
||||
与 SchemaIndexer 共用 ``get_embedder()``。Few-shot 默认使用 ``PersistentClient``
|
||||
(``FEWSHOT_CHROMA_PATH`` / ``./data/embeddings/chroma_fewshot``),与灌库脚本写入目录一致;
|
||||
仅当 ``FEWSHOT_CHROMA_EPHEMERAL=true`` 或显式 ``persist_to_disk=False`` 时使用内存 Chroma。
|
||||
集合名默认 ``fewshot_samples``。
|
||||
"""
|
||||
|
||||
@@ -36,14 +37,15 @@ class FewShotChromaStore:
|
||||
persist_dir: Optional[str] = None,
|
||||
collection_name: Optional[str] = None,
|
||||
*,
|
||||
persist_to_disk: bool = False,
|
||||
persist_to_disk: Optional[bool] = None,
|
||||
):
|
||||
"""
|
||||
Args:
|
||||
embedder: 编码器实例。
|
||||
persist_dir: 磁盘模式下的持久化目录;内存模式下仍解析为配置引用路径。
|
||||
persist_dir: Chroma 持久化根目录;内存模式下仍解析为配置引用路径。
|
||||
collection_name: 集合名;可空,空则读环境变量或默认。
|
||||
persist_to_disk: 为 True 时使用 ``PersistentClient`` 落盘(如灌库脚本)。
|
||||
persist_to_disk: 为 True/False 时强制磁盘或内存;为 None 时默认磁盘,除非环境变量
|
||||
``FEWSHOT_CHROMA_EPHEMERAL`` 为真。
|
||||
"""
|
||||
self.embedder = embedder
|
||||
# Chroma 的 collection 名;显式参数优先,否则读 FEWSHOT_CHROMA_COLLECTION,再回退默认
|
||||
@@ -53,8 +55,16 @@ class FewShotChromaStore:
|
||||
self.persist_dir = Path(
|
||||
(persist_dir or os.getenv("FEWSHOT_CHROMA_PATH") or DEFAULT_FEWSHOT_CHROMA_DIR).strip()
|
||||
)
|
||||
self.persist_to_disk = persist_to_disk
|
||||
if persist_to_disk:
|
||||
env_ephemeral = os.getenv("FEWSHOT_CHROMA_EPHEMERAL", "").lower() in (
|
||||
"1",
|
||||
"true",
|
||||
"yes",
|
||||
)
|
||||
if persist_to_disk is None:
|
||||
self.persist_to_disk = not env_ephemeral
|
||||
else:
|
||||
self.persist_to_disk = bool(persist_to_disk)
|
||||
if self.persist_to_disk:
|
||||
self.persist_dir.mkdir(parents=True, exist_ok=True)
|
||||
self.client = chromadb.PersistentClient(
|
||||
path=str(self.persist_dir),
|
||||
@@ -68,7 +78,11 @@ class FewShotChromaStore:
|
||||
name=self.collection_name,
|
||||
metadata={"hnsw:space": "cosine"},
|
||||
)
|
||||
backend = f"磁盘 {self.persist_dir}" if persist_to_disk else f"内存(配置路径={self.persist_dir})"
|
||||
backend = (
|
||||
f"磁盘 {self.persist_dir}"
|
||||
if self.persist_to_disk
|
||||
else f"内存(配置路径={self.persist_dir})"
|
||||
)
|
||||
logger.info(
|
||||
f"[OK] FewShotChromaStore: {backend} collection={self.collection_name} "
|
||||
f"count={self.collection.count()}"
|
||||
|
||||
Reference in New Issue
Block a user