mirror of
https://github.com/agentscope-ai/ReMe.git
synced 2026-10-09 03:20:54 +00:00
refactor(file_store): move sqlite3 imports inside initialization methods (#193)
* fix(core): handle chromadb import error gracefully - Changed CHROMADB_AVAILABLE flag to _CHROMADB_IMPORT_ERROR exception storage - Updated version from 0.3.1.7 to 0.3.1.8 - Modified import error handling to preserve original exception details - Removed hardcoded ImportError message in favor of dynamic exception raising - Added proper logger initialization using get_logger utility * refactor(file_store): move sqlite3 imports inside initialization methods - Moved sqlite3 import from module level to inside init methods - Removed unused import statement at top of file - Maintains same functionality while improving import organization - Prevents potential issues with early sqlite3 dependency loading * refactor(core): update import error handling with broader exception types - Changed ImportError to Exception for ray import error handling - Updated chromadb import error to use Exception instead of ImportError - Modified elasticsearch import error to catch general exceptions - Changed asyncpg import error handling from ImportError to Exception - Updated qdrant import error to use Exception instead of ImportError - Added explicit type hints for all import error variables as Exception | None
This commit is contained in:
parent
a97635752b
commit
d5c929722b
7 changed files with 15 additions and 13 deletions
|
|
@ -16,8 +16,8 @@ try:
|
|||
import chromadb
|
||||
from chromadb.config import Settings
|
||||
|
||||
_CHROMADB_IMPORT_ERROR: ImportError | None = None
|
||||
except ImportError as e:
|
||||
_CHROMADB_IMPORT_ERROR: Exception | None = None
|
||||
except Exception as e:
|
||||
_CHROMADB_IMPORT_ERROR = e
|
||||
chromadb = None
|
||||
Settings = None
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
"""SQLite storage backend for file store."""
|
||||
|
||||
import json
|
||||
import sqlite3
|
||||
|
||||
import struct
|
||||
import time
|
||||
|
||||
|
|
@ -29,6 +29,7 @@ class SqliteFileStore(BaseFileStore):
|
|||
def __init__(self, vec_ext_path: str = "", **kwargs):
|
||||
super().__init__(**kwargs)
|
||||
self.vec_ext_path = vec_ext_path
|
||||
import sqlite3
|
||||
|
||||
self.conn: sqlite3.Connection | None = None
|
||||
|
||||
|
|
@ -61,6 +62,7 @@ class SqliteFileStore(BaseFileStore):
|
|||
"""Initialize database and load extensions."""
|
||||
if self.conn is not None:
|
||||
return
|
||||
import sqlite3
|
||||
|
||||
self.conn = sqlite3.connect(self.db_path / "reme.db", check_same_thread=False)
|
||||
|
||||
|
|
|
|||
|
|
@ -10,11 +10,11 @@ from tqdm import tqdm
|
|||
from .base_op import BaseOp
|
||||
from ..base_dict import BaseDict
|
||||
|
||||
_RAY_IMPORT_ERROR = None
|
||||
_RAY_IMPORT_ERROR: Exception | None = None
|
||||
|
||||
try:
|
||||
import ray
|
||||
except ImportError as _e:
|
||||
except Exception as _e:
|
||||
_RAY_IMPORT_ERROR = _e
|
||||
ray = None
|
||||
|
||||
|
|
|
|||
|
|
@ -9,12 +9,12 @@ from .base_vector_store import BaseVectorStore
|
|||
from ..embedding import BaseEmbeddingModel
|
||||
from ..schema import VectorNode
|
||||
|
||||
_CHROMADB_IMPORT_ERROR = None
|
||||
_CHROMADB_IMPORT_ERROR: Exception | None = None
|
||||
|
||||
try:
|
||||
import chromadb
|
||||
from chromadb.config import Settings
|
||||
except ImportError as e:
|
||||
except Exception as e:
|
||||
_CHROMADB_IMPORT_ERROR = e
|
||||
chromadb = None
|
||||
Settings = None
|
||||
|
|
|
|||
|
|
@ -13,12 +13,12 @@ from .base_vector_store import BaseVectorStore
|
|||
from ..embedding import BaseEmbeddingModel
|
||||
from ..schema import VectorNode
|
||||
|
||||
_ELASTICSEARCH_IMPORT_ERROR = None
|
||||
_ELASTICSEARCH_IMPORT_ERROR: Exception | None = None
|
||||
|
||||
try:
|
||||
from elasticsearch import AsyncElasticsearch
|
||||
from elasticsearch.helpers import async_bulk
|
||||
except ImportError as e:
|
||||
except Exception as e:
|
||||
_ELASTICSEARCH_IMPORT_ERROR = e
|
||||
AsyncElasticsearch = None
|
||||
async_bulk = None
|
||||
|
|
|
|||
|
|
@ -11,12 +11,12 @@ from .base_vector_store import BaseVectorStore
|
|||
from ..embedding import BaseEmbeddingModel
|
||||
from ..schema import VectorNode
|
||||
|
||||
_ASYNCPG_IMPORT_ERROR = None
|
||||
_ASYNCPG_IMPORT_ERROR: Exception | None = None
|
||||
|
||||
try:
|
||||
import asyncpg
|
||||
from asyncpg import Pool
|
||||
except ImportError as e:
|
||||
except Exception as e:
|
||||
_ASYNCPG_IMPORT_ERROR = e
|
||||
asyncpg = None
|
||||
Pool = None
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ from .base_vector_store import BaseVectorStore
|
|||
from ..embedding import BaseEmbeddingModel
|
||||
from ..schema import VectorNode
|
||||
|
||||
_QDRANT_IMPORT_ERROR = None
|
||||
_QDRANT_IMPORT_ERROR: Exception | None = None
|
||||
|
||||
try:
|
||||
from qdrant_client import AsyncQdrantClient
|
||||
|
|
@ -23,7 +23,7 @@ try:
|
|||
Range,
|
||||
VectorParams,
|
||||
)
|
||||
except ImportError as e:
|
||||
except Exception as e:
|
||||
_QDRANT_IMPORT_ERROR = e
|
||||
AsyncQdrantClient = None
|
||||
Distance = None
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue