|
1 | 1 | from contextlib import asynccontextmanager |
2 | 2 | from pathlib import Path |
| 3 | +from typing import TYPE_CHECKING |
3 | 4 |
|
4 | 5 | from sqlalchemy import delete, func, select, text, update |
5 | 6 | from sqlalchemy.ext.asyncio import AsyncSession, async_sessionmaker, create_async_engine |
6 | 7 | from sqlmodel import col, desc |
7 | 8 |
|
8 | 9 | from astrbot.core import logger |
9 | | -from astrbot.core.db.vec_db.faiss_impl import FaissVecDB |
10 | 10 | from astrbot.core.knowledge_base.models import ( |
11 | 11 | BaseKBModel, |
12 | 12 | KBDocument, |
|
15 | 15 | ) |
16 | 16 | from astrbot.core.utils.astrbot_path import get_astrbot_knowledge_base_path |
17 | 17 |
|
| 18 | +if TYPE_CHECKING: |
| 19 | + from astrbot.core.db.vec_db.faiss_impl import FaissVecDB |
| 20 | + |
18 | 21 |
|
19 | 22 | class KBSQLiteDatabase: |
20 | 23 | def __init__(self, db_path: str | None = None) -> None: |
@@ -296,7 +299,7 @@ async def get_documents_with_metadata_batch( |
296 | 299 |
|
297 | 300 | return metadata_map |
298 | 301 |
|
299 | | - async def delete_document_by_id(self, doc_id: str, vec_db: FaissVecDB) -> None: |
| 302 | + async def delete_document_by_id(self, doc_id: str, vec_db: "FaissVecDB") -> None: |
300 | 303 | """删除单个文档及其相关数据""" |
301 | 304 | # 在知识库表中删除 |
302 | 305 | async with self.get_db() as session, session.begin(): |
@@ -324,7 +327,7 @@ async def get_media_by_id(self, media_id: str) -> KBMedia | None: |
324 | 327 | result = await session.execute(stmt) |
325 | 328 | return result.scalar_one_or_none() |
326 | 329 |
|
327 | | - async def update_kb_stats(self, kb_id: str, vec_db: FaissVecDB) -> None: |
| 330 | + async def update_kb_stats(self, kb_id: str, vec_db: "FaissVecDB") -> None: |
328 | 331 | """更新知识库统计信息""" |
329 | 332 | chunk_cnt = await vec_db.count_documents() |
330 | 333 |
|
|
0 commit comments