ruff
This commit is contained in:
@@ -100,10 +100,10 @@ class VectorStore:
|
||||
|
||||
# 处理额外的元数据,将 list 转换为 JSON 字符串
|
||||
for key, value in node.metadata.items():
|
||||
if isinstance(value, (list, dict)):
|
||||
if isinstance(value, list | dict):
|
||||
import orjson
|
||||
metadata[key] = orjson.dumps(value, option=orjson.OPT_NON_STR_KEYS).decode("utf-8")
|
||||
elif isinstance(value, (str, int, float, bool)) or value is None:
|
||||
elif isinstance(value, str | int | float | bool) or value is None:
|
||||
metadata[key] = value
|
||||
else:
|
||||
metadata[key] = str(value)
|
||||
@@ -149,9 +149,9 @@ class VectorStore:
|
||||
"created_at": n.created_at.isoformat(),
|
||||
}
|
||||
for key, value in n.metadata.items():
|
||||
if isinstance(value, (list, dict)):
|
||||
if isinstance(value, list | dict):
|
||||
metadata[key] = orjson.dumps(value, option=orjson.OPT_NON_STR_KEYS).decode("utf-8")
|
||||
elif isinstance(value, (str, int, float, bool)) or value is None:
|
||||
elif isinstance(value, str | int | float | bool) or value is None:
|
||||
metadata[key] = value # type: ignore
|
||||
else:
|
||||
metadata[key] = str(value)
|
||||
|
||||
@@ -4,8 +4,6 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
|
||||
import numpy as np
|
||||
|
||||
from src.common.logger import get_logger
|
||||
@@ -72,7 +70,7 @@ class EmbeddingGenerator:
|
||||
logger.warning(f"⚠️ Embedding API 初始化失败: {e}")
|
||||
self._api_available = False
|
||||
|
||||
|
||||
|
||||
async def generate(self, text: str) -> np.ndarray | None:
|
||||
"""
|
||||
生成单个文本的嵌入向量
|
||||
@@ -130,7 +128,7 @@ class EmbeddingGenerator:
|
||||
logger.debug(f"API 嵌入生成失败: {e}")
|
||||
return None
|
||||
|
||||
|
||||
|
||||
def _get_dimension(self) -> int:
|
||||
"""获取嵌入维度"""
|
||||
# 优先使用 API 维度
|
||||
|
||||
Reference in New Issue
Block a user