-
Notifications
You must be signed in to change notification settings - Fork 1.3k
feat: Enable Vector database and retrieve_online_documents API #4061
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
41 commits
Select commit
Hold shift + click to select a range
713768e
feat: add document store
HaoXuAI 58d5d94
feat: add document store
HaoXuAI 2cd73d1
feat: add document store
HaoXuAI d2e0a59
feat: add document store
HaoXuAI 7079e7f
remove DocumentStore
HaoXuAI 8c9ee97
format
HaoXuAI 513dd39
Merge branch 'master' into feat-documentstore
HaoXuAI 29d98cd
format
HaoXuAI 11eb97f
format
HaoXuAI 865baf2
format
HaoXuAI 47cd117
format
HaoXuAI 3f9f59f
format
HaoXuAI 7935071
remove unused vars
HaoXuAI ba39f93
add test
HaoXuAI cf53c71
add test
HaoXuAI 92046af
format
HaoXuAI d0acd2d
format
HaoXuAI cc45f73
format
HaoXuAI 006b5c6
format
HaoXuAI 6e0ba03
format
HaoXuAI a2302be
fix not implemented issue
HaoXuAI 2e6fc55
fix not implemented issue
HaoXuAI 3cbbf21
fix test
HaoXuAI ec32764
format
HaoXuAI e2d8008
format
HaoXuAI 523d20f
format
HaoXuAI 5cd085d
format
HaoXuAI 795699e
format
HaoXuAI 67b007f
format
HaoXuAI 33b46bd
update testcontainer
HaoXuAI 82fe5f1
format
HaoXuAI 0618378
fix postgres integration test
HaoXuAI 7de2016
format
HaoXuAI 92fed1d
fix postgres test
HaoXuAI d4f2639
fix postgres test
HaoXuAI 396d7de
fix postgres test
HaoXuAI 6c38b92
fix postgres test
HaoXuAI f763dc9
fix postgres test
HaoXuAI 818c055
format
HaoXuAI a51b555
format
HaoXuAI 2624b22
format
HaoXuAI 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
Next
Next commit
feat: add document store
- Loading branch information
commit 713768e036443ecf404437685a18ee354bd087fd
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
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -35,6 +35,7 @@ | |||||
|
|
||||||
| import pandas as pd | ||||||
| import pyarrow as pa | ||||||
| import numpy as np | ||||||
| from colorama import Fore, Style | ||||||
| from google.protobuf.timestamp_pb2 import Timestamp | ||||||
| from tqdm import tqdm | ||||||
|
|
@@ -1684,6 +1685,62 @@ def _get_online_features( | |||||
| ) | ||||||
| return OnlineResponse(online_features_response) | ||||||
|
|
||||||
| @log_exceptions_and_usage | ||||||
| def get_top_k_document_features(self, | ||||||
| feature: Union[str, FeatureService], | ||||||
| document: Union[str, np.ndarray], | ||||||
| top_k: int, | ||||||
| ) -> OnlineResponse: | ||||||
| """ | ||||||
| Retrieves the top k cloeses document features. | ||||||
|
|
||||||
| Args: | ||||||
| feature: The list of document features that should be retrieved from the online document store. These features can be | ||||||
| specified either as a list of string document feature references or as a feature service. String feature | ||||||
| references must have format "feature_view:feature", e.g, "document_fv:document_embedding_feature". | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| document: The document to retrieve the closest document features for. | ||||||
| top_k: The number of closest document features to retrieve. | ||||||
| """ | ||||||
| return self._get_top_k_document_features( | ||||||
| feature=feature, | ||||||
| document=document, | ||||||
| top_k=top_k, | ||||||
| ) | ||||||
|
|
||||||
| def _get_top_k_document_features( | ||||||
| self, | ||||||
| feature: Union[str, FeatureService], | ||||||
| document: Union[str, np.ndarray], | ||||||
| top_k: int, | ||||||
| ): | ||||||
| ( | ||||||
| requested_feature_views, | ||||||
| requested_on_demand_feature_views | ||||||
| ) = self._get_feature_views_to_use( | ||||||
| features=[feature], | ||||||
| allow_cache=True, | ||||||
| hide_dummy_entity=False | ||||||
| ) | ||||||
| requested_feature = feature.split(":")[1] if isinstance(feature, str) else feature | ||||||
| provider = self._get_provider() | ||||||
| document_features = self._search_from_document_store( | ||||||
| provider, | ||||||
| requested_feature_views[0], | ||||||
| requested_feature, | ||||||
| document, | ||||||
| top_k, | ||||||
| ) | ||||||
| online_features_response = GetOnlineFeaturesResponse(results=[]) | ||||||
| self._populate_response_from_feature_data( | ||||||
| document_features, | ||||||
| [], | ||||||
| online_features_response, | ||||||
| False, | ||||||
| requested_feature, | ||||||
| requested_feature_views[0] | ||||||
| ) | ||||||
| return OnlineResponse(online_features_response) | ||||||
|
|
||||||
| @staticmethod | ||||||
| def _get_columnar_entity_values( | ||||||
| rowise: Optional[List[Dict[str, Any]]], columnar: Optional[Dict[str, List[Any]]] | ||||||
|
|
@@ -1900,6 +1957,27 @@ def _read_from_online_store( | |||||
| read_row_protos.append((event_timestamps, statuses, values)) | ||||||
| return read_row_protos | ||||||
|
|
||||||
| def _search_from_document_store( | ||||||
| self, | ||||||
| provider: Provider, | ||||||
| table: FeatureView, | ||||||
| requested_feature: str, | ||||||
| document: Union[str, np.ndarray], | ||||||
| top_k: int, | ||||||
| ) -> List[Tuple[List[Timestamp], List["FieldStatus.ValueType"], List[Value]]]: | ||||||
| """ | ||||||
| Search and return document features from the online document store. | ||||||
| """ | ||||||
| documents = provider.online_search( | ||||||
| config=self.config, | ||||||
| table=table, | ||||||
| requested_feature=requested_feature, | ||||||
| document=document, | ||||||
| top_k=top_k, | ||||||
| ) | ||||||
| return documents | ||||||
|
|
||||||
|
|
||||||
| @staticmethod | ||||||
| def _populate_response_from_feature_data( | ||||||
| feature_data: Iterable[ | ||||||
|
|
||||||
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,38 @@ | ||
| from abc import abstractmethod | ||
| from datetime import datetime | ||
| from feast.feature_view import FeatureView | ||
| from feast.protos.feast.types.Value_pb2 import Value as ValueProto | ||
| from feast.repo_config import RepoConfig, FeastConfigBaseModel | ||
| from infra.online_stores.online_store import OnlineStore | ||
| from typing import Optional, List, Tuple, Dict | ||
| import numpy as np | ||
|
|
||
|
|
||
| class DocumentStoreIndexConfig(FeastConfigBaseModel): | ||
| embedding_type: Optional[str] | ||
|
|
||
|
|
||
| class DocumentStore(OnlineStore): | ||
| index: Optional[str] | ||
|
|
||
| @abstractmethod | ||
| def online_search(self, | ||
| config: RepoConfig, | ||
| table: FeatureView, | ||
| requested_feature: str, | ||
| embeddings: np.ndarray, | ||
| top_k: int, | ||
| ) -> List[Tuple[Optional[datetime], Optional[Dict[str, ValueProto]]]]: | ||
| raise NotImplementedError( | ||
| "You have to implement this!" | ||
| ) | ||
|
|
||
| @abstractmethod | ||
| def create_index(self, | ||
| config: RepoConfig, | ||
| index: str, | ||
| index_config: DocumentStoreIndexConfig | ||
| ): | ||
| raise NotImplementedError( | ||
| "You have to implement this!" | ||
| ) |
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
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.