Skip to content

Commit d095b96

Browse files
authored
feat: Implement and enhance remote document retrieval functionality (#5487)
* Remotely retrieve the docs Signed-off-by: jyejare <[email protected]> * Feature server rectified for documents retrival Signed-off-by: jyejare <[email protected]> * Updates to remote retrival for response extraction Signed-off-by: jyejare <[email protected]> * Remote retrive online doc v2 Signed-off-by: jyejare <[email protected]> * Unit tests for Remote docuemnts retrival Signed-off-by: jyejare <[email protected]> * Fixed checks and comments Signed-off-by: jyejare <[email protected]> --------- Signed-off-by: jyejare <[email protected]>
1 parent a4eef38 commit d095b96

File tree

5 files changed

+724
-15
lines changed

5 files changed

+724
-15
lines changed

sdk/python/feast/feature_server.py

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import traceback
77
from contextlib import asynccontextmanager
88
from importlib import resources as importlib_resources
9-
from typing import Any, Dict, List, Optional
9+
from typing import Any, Dict, List, Optional, Union
1010

1111
import pandas as pd
1212
import psutil
@@ -86,10 +86,18 @@ class MaterializeIncrementalRequest(BaseModel):
8686
class GetOnlineFeaturesRequest(BaseModel):
8787
entities: Dict[str, List[Any]]
8888
feature_service: Optional[str] = None
89-
features: Optional[List[str]] = None
89+
features: List[str] = []
9090
full_feature_names: bool = False
91-
query_embedding: Optional[List[float]] = None
91+
92+
93+
class GetOnlineDocumentsRequest(BaseModel):
94+
feature_service: Optional[str] = None
95+
features: List[str] = []
96+
full_feature_names: bool = False
97+
top_k: Optional[int] = None
98+
query: Optional[List[float]] = None
9299
query_string: Optional[str] = None
100+
api_version: Optional[int] = 1
93101

94102

95103
class ChatMessage(BaseModel):
@@ -110,7 +118,10 @@ class SaveDocumentRequest(BaseModel):
110118
data: dict
111119

112120

113-
def _get_features(request: GetOnlineFeaturesRequest, store: "feast.FeatureStore"):
121+
def _get_features(
122+
request: Union[GetOnlineFeaturesRequest, GetOnlineDocumentsRequest],
123+
store: "feast.FeatureStore",
124+
):
114125
if request.feature_service:
115126
feature_service = store.get_feature_service(
116127
request.feature_service, allow_cache=True
@@ -246,24 +257,26 @@ async def get_online_features(request: GetOnlineFeaturesRequest) -> Dict[str, An
246257
dependencies=[Depends(inject_user_details)],
247258
)
248259
async def retrieve_online_documents(
249-
request: GetOnlineFeaturesRequest,
260+
request: GetOnlineDocumentsRequest,
250261
) -> Dict[str, Any]:
251262
logger.warning(
252263
"This endpoint is in alpha and will be moved to /get-online-features when stable."
253264
)
254265
# Initialize parameters for FeatureStore.retrieve_online_documents_v2(...) call
255266
features = await run_in_threadpool(_get_features, request, store)
256267

257-
read_params = dict(
258-
features=features,
259-
full_feature_names=request.full_feature_names,
260-
query=request.query_embedding,
261-
query_string=request.query_string,
262-
)
268+
read_params = dict(features=features, query=request.query, top_k=request.top_k)
269+
if request.api_version == 2 and request.query_string is not None:
270+
read_params["query_string"] = request.query_string
263271

264-
response = await run_in_threadpool(
265-
lambda: store.retrieve_online_documents_v2(**read_params) # type: ignore
266-
)
272+
if request.api_version == 2:
273+
response = await run_in_threadpool(
274+
lambda: store.retrieve_online_documents_v2(**read_params) # type: ignore
275+
)
276+
else:
277+
response = await run_in_threadpool(
278+
lambda: store.retrieve_online_documents(**read_params) # type: ignore
279+
)
267280

268281
# Convert the Protobuf object to JSON and return it
269282
response_dict = await run_in_threadpool(

sdk/python/feast/feature_store.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2413,6 +2413,11 @@ def _retrieve_from_online_store_v2(
24132413
output_len=output_len,
24142414
)
24152415

2416+
utils._populate_result_rows_from_columnar(
2417+
online_features_response=online_features_response,
2418+
data=entity_key_dict,
2419+
)
2420+
24162421
return OnlineResponse(online_features_response)
24172422

24182423
def serve(

0 commit comments

Comments
 (0)