Skip to content

Commit 7bb0b12

Browse files
Zhe YuDavidyz
authored andcommitted
docs about database connectors.
1 parent 13997d2 commit 7bb0b12

2 files changed

Lines changed: 27 additions & 0 deletions

File tree

src/vectorcode/database/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,13 @@ def get_database_connector(config: Config) -> DatabaseConnectorBase:
1313
This allow them to be lazy-imported. This also allow us to keep the main package
1414
lightweight because we don't have to include dependencies for EVERY database.
1515
16+
> Raises a `ValueError` in case the database connector is not supported.
1617
"""
1718
cls: Optional[Type[DatabaseConnectorBase]] = None
1819

1920
if not config.db_type.endswith("Connector"):
2021
config.db_type = f"{config.db_type}Connector"
22+
logger.debug(f"Correcting the name of the db connector to {config.db_type}")
2123

2224
match config.db_type:
2325
case "ChromaDB0Connector":
@@ -28,3 +30,6 @@ def get_database_connector(config: Config) -> DatabaseConnectorBase:
2830
raise ValueError(f"Unrecognised database type: {config.db_type}")
2931

3032
return cls.create(config)
33+
34+
35+
__all__ = ["get_database_connector"]

src/vectorcode/database/base.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,28 @@
1919
logger = logging.getLogger(name=__name__)
2020

2121

22+
"""
23+
For developers:
24+
25+
To implement a custom database connector, you should inherit the following
26+
`DatabaseConnectorBase` class and implement ALL abstract methods.
27+
28+
You should also try to wrap the exceptions with the ones in
29+
`src/vectorcode/database/errors.py` where appropriate, because this helps the
30+
CLI/LSP/MCP interfaces to handle some common edge cases. To do this, you should do the following in a try-except block:
31+
```python
32+
from vectorcode.database.errors import CollectionNotFoundError
33+
34+
try:
35+
some_action_here()
36+
except SomeCustomException as e:
37+
raise CollectionNotFoundError("The collection was not found.") from e
38+
```
39+
This will preserve the correct call stack in the error message and makes debugging
40+
easier.
41+
"""
42+
43+
2244
class DatabaseConnectorBase(ABC): # pragma: nocover
2345
@classmethod
2446
def create(cls, configs: Config):

0 commit comments

Comments
 (0)