-
Notifications
You must be signed in to change notification settings - Fork 355
enable injection for Collection and CollectionAdaptor #414
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
zhougit86
wants to merge
2
commits into
volcengine:main
Choose a base branch
from
zhougit86:feat/enable_custom_loading_adaptor
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
2 commits
Select commit
Hold shift + click to select a range
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
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
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,181 @@ | ||
| from typing import Any, Dict, List, Optional | ||
| from openviking.storage.vectordb.collection.collection import ICollection | ||
| from openviking.storage.vectordb.collection.result import AggregateResult, SearchResult | ||
| from openviking.storage.vectordb.index.index import IIndex | ||
|
|
||
| from openviking.storage.vectordb_adapters.base import CollectionAdapter | ||
| from openviking.storage.vectordb.collection.collection import Collection | ||
|
|
||
| class MockCollectionAdapter(CollectionAdapter): | ||
| """ | ||
| Mock adapter for testing dynamic loading. | ||
| Inherits from CollectionAdapter and wraps MockCollection. | ||
| """ | ||
| def __init__(self, collection_name: str, custom_param1: str = "", custom_param2: int = 0): | ||
| super().__init__(collection_name=collection_name) | ||
| self.mode = "mock" | ||
| self.custom_param1 = custom_param1 | ||
| self.custom_param2 = custom_param2 | ||
|
|
||
| @classmethod | ||
| def from_config(cls, config: Any) -> "MockCollectionAdapter": | ||
| return cls( | ||
| collection_name=config.name or "mock_collection", | ||
| custom_param1=getattr(config, "custom_param1", ""), | ||
| custom_param2=getattr(config, "custom_param2", 0) | ||
| ) | ||
|
|
||
| def _load_existing_collection_if_needed(self) -> None: | ||
| if self._collection is None: | ||
| # Create a dummy collection wrapping MockCollection | ||
| self._collection = MockCollection(self.custom_param1, self.custom_param2) | ||
|
|
||
| def _create_backend_collection(self, meta: Dict[str, Any]) -> Collection: | ||
| return MockCollection(self.custom_param1, self.custom_param2) | ||
|
|
||
| class MockCollection(ICollection): | ||
| def __init__(self, custom_param1: str, custom_param2: int, meta_data: Optional[Dict[str, Any]] = None, **kwargs): | ||
| super().__init__() | ||
| self.meta_data = meta_data if meta_data is not None else {} | ||
|
|
||
| self.custom_param1 = custom_param1 | ||
| self.custom_param2 = custom_param2 | ||
|
|
||
| # Store extra kwargs (including host/headers if passed but not used explicitly) | ||
| self.kwargs = kwargs | ||
|
|
||
| # Verify that we can access values passed during initialization | ||
| if self.meta_data and "test_verification" in self.meta_data: | ||
| print(f"MockCollection initialized with custom_param1={self.custom_param1}, custom_param2={self.custom_param2}, kwargs={kwargs}") | ||
|
|
||
| def update(self, fields: Optional[Dict[str, Any]] = None, description: Optional[str] = None): | ||
| raise NotImplementedError("MockCollection.update is not supported") | ||
|
|
||
| def get_meta_data(self): | ||
| raise NotImplementedError("MockCollection.get_meta_data is not supported") | ||
|
|
||
| def close(self): | ||
| # No-op for mock | ||
| pass | ||
|
|
||
| def drop(self): | ||
| # No-op for mock | ||
| pass | ||
|
|
||
| def create_index(self, index_name: str, meta_data: Dict[str, Any]) -> IIndex: | ||
| raise NotImplementedError("MockCollection.create_index is not supported") | ||
|
|
||
| def has_index(self, index_name: str) -> bool: | ||
| raise NotImplementedError("MockCollection.has_index is not supported") | ||
|
|
||
| def get_index(self, index_name: str) -> Optional[IIndex]: | ||
| raise NotImplementedError("MockCollection.get_index is not supported") | ||
|
|
||
| def search_by_vector( | ||
| self, | ||
| index_name: str, | ||
| dense_vector: Optional[List[float]] = None, | ||
| limit: int = 10, | ||
| offset: int = 0, | ||
| filters: Optional[Dict[str, Any]] = None, | ||
| sparse_vector: Optional[Dict[str, float]] = None, | ||
| output_fields: Optional[List[str]] = None, | ||
| ) -> SearchResult: | ||
| raise NotImplementedError("MockCollection.search_by_vector is not supported") | ||
|
|
||
| def search_by_keywords( | ||
| self, | ||
| index_name: str, | ||
| keywords: Optional[List[str]] = None, | ||
| query: Optional[str] = None, | ||
| limit: int = 10, | ||
| offset: int = 0, | ||
| filters: Optional[Dict[str, Any]] = None, | ||
| output_fields: Optional[List[str]] = None, | ||
| ) -> SearchResult: | ||
| raise NotImplementedError("MockCollection.search_by_keywords is not supported") | ||
|
|
||
| def search_by_id( | ||
| self, | ||
| index_name: str, | ||
| id: Any, | ||
| limit: int = 10, | ||
| offset: int = 0, | ||
| filters: Optional[Dict[str, Any]] = None, | ||
| output_fields: Optional[List[str]] = None, | ||
| ) -> SearchResult: | ||
| raise NotImplementedError("MockCollection.search_by_id is not supported") | ||
|
|
||
| def search_by_multimodal( | ||
| self, | ||
| index_name: str, | ||
| text: Optional[str], | ||
| image: Optional[Any], | ||
| video: Optional[Any], | ||
| limit: int = 10, | ||
| offset: int = 0, | ||
| filters: Optional[Dict[str, Any]] = None, | ||
| output_fields: Optional[List[str]] = None, | ||
| ) -> SearchResult: | ||
| raise NotImplementedError("MockCollection.search_by_multimodal is not supported") | ||
|
|
||
| def search_by_random( | ||
| self, | ||
| index_name: str, | ||
| limit: int = 10, | ||
| offset: int = 0, | ||
| filters: Optional[Dict[str, Any]] = None, | ||
| output_fields: Optional[List[str]] = None, | ||
| ) -> SearchResult: | ||
| raise NotImplementedError("MockCollection.search_by_random is not supported") | ||
|
|
||
| def search_by_scalar( | ||
| self, | ||
| index_name: str, | ||
| field: str, | ||
| order: Optional[str] = "desc", | ||
| limit: int = 10, | ||
| offset: int = 0, | ||
| filters: Optional[Dict[str, Any]] = None, | ||
| output_fields: Optional[List[str]] = None, | ||
| ) -> SearchResult: | ||
| raise NotImplementedError("MockCollection.search_by_scalar is not supported") | ||
|
|
||
| def update_index( | ||
| self, | ||
| index_name: str, | ||
| scalar_index: Optional[Dict[str, Any]] = None, | ||
| description: Optional[str] = None, | ||
| ): | ||
| raise NotImplementedError("MockCollection.update_index is not supported") | ||
|
|
||
| def get_index_meta_data(self, index_name: str): | ||
| raise NotImplementedError("MockCollection.get_index_meta_data is not supported") | ||
|
|
||
| def list_indexes(self): | ||
| raise NotImplementedError("MockCollection.list_indexes is not supported") | ||
|
|
||
| def drop_index(self, index_name: str): | ||
| raise NotImplementedError("MockCollection.drop_index is not supported") | ||
|
|
||
| def upsert_data(self, data_list: List[Dict[str, Any]], ttl=0): | ||
| raise NotImplementedError("MockCollection.upsert_data is not supported") | ||
|
|
||
| def fetch_data(self, primary_keys: List[Any]): | ||
| raise NotImplementedError("MockCollection.fetch_data is not supported") | ||
|
|
||
| def delete_data(self, primary_keys: List[Any]): | ||
| raise NotImplementedError("MockCollection.delete_data is not supported") | ||
|
|
||
| def delete_all_data(self): | ||
| raise NotImplementedError("MockCollection.delete_all_data is not supported") | ||
|
|
||
| def aggregate_data( | ||
| self, | ||
| index_name: str, | ||
| op: str = "count", | ||
| field: Optional[str] = None, | ||
| filters: Optional[Dict[str, Any]] = None, | ||
| cond: Optional[Dict[str, Any]] = None, | ||
| ) -> AggregateResult: | ||
| raise NotImplementedError("MockCollection.aggregate_data is not supported") |
Oops, something went wrong.
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.
这个 config 有更新 config 下的代码吗,好像没看到