base.py
886 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
"""数据库抽象基类,定义统一的CRUD接口."""
from abc import ABC, abstractmethod
from typing import Any, Dict, List, Optional
class VectorDBClient(ABC):
"""向量数据库客户端抽象基类.
定义了统一的向量数据CRUD接口,支持Elasticsearch和PostgreSQL等后端。
"""
@abstractmethod
async def connect(self) -> None:
"""建立数据库连接."""
pass
@abstractmethod
async def disconnect(self) -> None:
"""断开数据库连接."""
pass
@abstractmethod
async def health_check(self) -> bool:
"""检查数据库连接健康状态.
Returns:
bool: 连接正常返回True,否则返回False
"""
pass
class TableInit(ABC):
@abstractmethod
async def create_table(self, name, embedding_version, embedding_dim) -> None:
pass