-
Notifications
You must be signed in to change notification settings - Fork 397
feat(logosdb): add LogosDB vector database integration #782
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jose-compu
wants to merge
4
commits into
zilliztech:main
Choose a base branch
from
jose-compu:feat/logosdb-integration
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
a9ec9c6
feat(logosdb): add LogosDB vector database integration
jose-compu 01e0fd0
fix(logosdb): replace os.path.exists with Path.exists to satisfy PTH1…
jose-compu 812eea6
fix(logosdb): move import to correct alphabetical position to satisfy…
jose-compu b932872
fix(logosdb): disable concurrent search (single-process embedded DB)
jose-compu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| from typing import Annotated, Unpack | ||
|
|
||
| import click | ||
|
|
||
| from vectordb_bench.backend.clients import DB | ||
| from vectordb_bench.cli.cli import ( | ||
| CommonTypedDict, | ||
| cli, | ||
| click_parameter_decorators_from_typed_dict, | ||
| run, | ||
| ) | ||
|
|
||
| DBTYPE = DB.LogosDB | ||
|
|
||
|
|
||
| class LogosDBTypedDict(CommonTypedDict): | ||
| uri: Annotated[ | ||
| str, | ||
| click.option( | ||
| "--uri", | ||
| type=str, | ||
| help="Path to LogosDB directory (local embedded DB)", | ||
| required=False, | ||
| default="/tmp/vectordbbench_logosdb", | ||
| show_default=True, | ||
| ), | ||
| ] | ||
|
|
||
|
|
||
| @cli.command() | ||
| @click_parameter_decorators_from_typed_dict(LogosDBTypedDict) | ||
| def LogosDB(**parameters: Unpack[LogosDBTypedDict]): | ||
| from .config import LogosDBConfig, LogosDBIndexConfig | ||
|
|
||
| # LogosDB is documented as single-process; disable concurrent search | ||
| # until a thread-safe concurrent runner is available. | ||
| parameters["search_concurrent"] = False | ||
|
|
||
| run( | ||
| db=DBTYPE, | ||
| db_config=LogosDBConfig(uri=parameters["uri"]), | ||
| db_case_config=LogosDBIndexConfig(), | ||
| **parameters, | ||
| ) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| from pydantic import BaseModel | ||
|
|
||
| from ..api import DBCaseConfig, DBConfig, MetricType | ||
|
|
||
|
|
||
| class LogosDBConfig(DBConfig): | ||
| uri: str = "/tmp/vectordbbench_logosdb" | ||
|
|
||
| def to_dict(self) -> dict: | ||
| return {"uri": self.uri} | ||
|
|
||
|
|
||
| class LogosDBIndexConfig(BaseModel, DBCaseConfig): | ||
| metric_type: MetricType | None = None | ||
|
|
||
| def parse_metric(self) -> int: | ||
| import logosdb | ||
|
|
||
| if self.metric_type == MetricType.L2: | ||
| return logosdb.DIST_L2 | ||
| if self.metric_type == MetricType.IP: | ||
| return logosdb.DIST_IP | ||
| return logosdb.DIST_COSINE | ||
|
|
||
| def index_param(self) -> dict: | ||
| return {} | ||
|
|
||
| def search_param(self) -> dict: | ||
| return {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| import logging | ||
| import shutil | ||
| from collections.abc import Iterable | ||
| from contextlib import contextmanager | ||
| from pathlib import Path | ||
|
|
||
| import numpy as np | ||
|
|
||
| from ..api import VectorDB | ||
| from .config import LogosDBIndexConfig | ||
|
|
||
| log = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| class LogosDB(VectorDB): | ||
| def __init__( | ||
| self, | ||
| dim: int, | ||
| db_config: dict, | ||
| db_case_config: LogosDBIndexConfig, | ||
| collection_name: str = "LogosDBCollection", | ||
| drop_old: bool = False, | ||
| name: str = "LogosDB", | ||
| **kwargs, | ||
| ): | ||
| self.name = name | ||
| self.db_config = db_config | ||
| self.case_config = db_case_config | ||
| self.dim = dim | ||
| self.uri = db_config["uri"] | ||
| self.db = None | ||
|
|
||
| if drop_old and Path(self.uri).exists(): | ||
| log.info(f"{self.name} drop_old: removing {self.uri}") | ||
| shutil.rmtree(self.uri) | ||
|
|
||
| import logosdb as _logosdb | ||
|
|
||
| distance = self.case_config.parse_metric() | ||
| db = _logosdb.DB(self.uri, dim=self.dim, distance=distance) | ||
| log.info(f"{self.name} initialized at {self.uri} dim={dim} distance={distance}") | ||
| del db | ||
|
|
||
| @contextmanager | ||
| def init(self): | ||
| import logosdb as _logosdb | ||
|
|
||
| distance = self.case_config.parse_metric() | ||
| self.db = _logosdb.DB(self.uri, dim=self.dim, distance=distance) | ||
| try: | ||
| yield | ||
| finally: | ||
| del self.db | ||
| self.db = None | ||
|
|
||
| def insert_embeddings( | ||
| self, | ||
| embeddings: Iterable[list[float]], | ||
| metadata: list[int], | ||
| **kwargs, | ||
| ) -> tuple[int, Exception]: | ||
| assert self.db is not None | ||
| try: | ||
| embeddings_arr = np.array(list(embeddings), dtype=np.float32) | ||
| texts = [str(m) for m in metadata] | ||
| self.db.put_batch(embeddings_arr, texts=texts) | ||
| return len(metadata), None | ||
| except Exception as e: | ||
| log.warning(f"{self.name} insert_embeddings error: {e}") | ||
| return 0, e | ||
|
|
||
| def search_embedding( | ||
| self, | ||
| query: list[float], | ||
| k: int = 100, | ||
| filters: dict | None = None, | ||
| timeout: int | None = None, | ||
| ) -> list[int]: | ||
| assert self.db is not None | ||
| q = np.array(query, dtype=np.float32) | ||
| hits = self.db.search(q, top_k=k) | ||
| return [int(h.text) for h in hits] | ||
|
|
||
| def optimize(self, data_size: int | None = None): | ||
| log.info(f"{self.name} optimize: HNSW index is built incrementally, no explicit step needed") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
must-change:
LogosDBinheritssearch_concurrent=TruefromCommonTypedDict, but LogosDB documents one DB directory as single-process while VDBBench concurrent search starts multipleProcessPoolExecutorworkers against the same--uri. The default command can fail or report invalid concurrent-search results after loading. Setparameters["search_concurrent"] = Falseor reject--search-concurrentfor LogosDB until a supported single-process concurrent runner exists.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for catching this. Fixed in the latest commit by hard-setting
parameters["search_concurrent"] = Falsein the CLI handler.Quick note: I did test multi-process concurrent reads empirically (4
Poolworkers opening the same DB path and running 50 searches each) and all succeeded without errors (LogosDB's memory-mapped storage appears safe for concurrent readers). That said, since the official docs declare it single-process, disabling concurrent search is the right conservative call for now. Can revisit if/when LogosDB formally documents multi-reader support.Fixed here: b932872