Skip to content

Commit 6607d3d

Browse files
feat: Adding retrieve_online_documents endpoint (#5002)
* feat: Adding retrieve_online_documents endpoint Signed-off-by: Francisco Javier Arceo <farceo@redhat.com> * updated feature server Signed-off-by: Francisco Javier Arceo <farceo@redhat.com> --------- Signed-off-by: Francisco Javier Arceo <farceo@redhat.com>
1 parent a8842b0 commit 6607d3d

File tree

2 files changed

+42
-8
lines changed

2 files changed

+42
-8
lines changed

docs/reference/feature-servers/python-feature-server.md

+8-7
Original file line numberDiff line numberDiff line change
@@ -226,13 +226,14 @@ feast serve --key /path/to/key.pem --cert /path/to/cert.pem
226226

227227
## API Endpoints and Permissions
228228

229-
| Endpoint | Resource Type | Permission | Description |
230-
| ---------------------------- |---------------------------------|-------------------------------------------------------| ------------------------------------------------------------------------ |
231-
| /get-online-features | FeatureView,OnDemandFeatureView | Read Online | Get online features from the feature store |
232-
| /push | FeatureView | Write Online, Write Offline, Write Online and Offline | Push features to the feature store (online, offline, or both) |
233-
| /write-to-online-store | FeatureView | Write Online | Write features to the online store |
234-
| /materialize | FeatureView | Write Online | Materialize features within a specified time range |
235-
| /materialize-incremental | FeatureView | Write Online | Incrementally materialize features up to a specified timestamp |
229+
| Endpoint | Resource Type | Permission | Description |
230+
|----------------------------|---------------------------------|-------------------------------------------------------|----------------------------------------------------------------|
231+
| /get-online-features | FeatureView,OnDemandFeatureView | Read Online | Get online features from the feature store |
232+
| /retrieve-online-documents | FeatureView | Read Online | Retrieve online documents from the feature store for RAG |
233+
| /push | FeatureView | Write Online, Write Offline, Write Online and Offline | Push features to the feature store (online, offline, or both) |
234+
| /write-to-online-store | FeatureView | Write Online | Write features to the online store |
235+
| /materialize | FeatureView | Write Online | Materialize features within a specified time range |
236+
| /materialize-incremental | FeatureView | Write Online | Incrementally materialize features up to a specified timestamp |
236237

237238
## How to configure Authentication and Authorization ?
238239

sdk/python/feast/feature_server.py

+34-1
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ class GetOnlineFeaturesRequest(BaseModel):
7474
feature_service: Optional[str] = None
7575
features: Optional[List[str]] = None
7676
full_feature_names: bool = False
77+
query_embedding: Optional[List[float]] = None
7778

7879

7980
def _get_features(request: GetOnlineFeaturesRequest, store: "feast.FeatureStore"):
@@ -104,7 +105,6 @@ def _get_features(request: GetOnlineFeaturesRequest, store: "feast.FeatureStore"
104105
resource=od_feature_view, actions=[AuthzedAction.READ_ONLINE]
105106
)
106107
features = request.features # type: ignore
107-
108108
return features
109109

110110

@@ -177,6 +177,39 @@ async def get_online_features(request: GetOnlineFeaturesRequest) -> Dict[str, An
177177
)
178178
return response_dict
179179

180+
@app.post(
181+
"/retrieve-online-documents",
182+
dependencies=[Depends(inject_user_details)],
183+
)
184+
async def retrieve_online_documents(
185+
request: GetOnlineFeaturesRequest,
186+
) -> Dict[str, Any]:
187+
logger.warn(
188+
"This endpoint is in alpha and will be moved to /get-online-features when stable."
189+
)
190+
# Initialize parameters for FeatureStore.retrieve_online_documents_v2(...) call
191+
features = await run_in_threadpool(_get_features, request, store)
192+
193+
read_params = dict(
194+
features=features,
195+
entity_rows=request.entities,
196+
full_feature_names=request.full_feature_names,
197+
query=request.query_embedding,
198+
)
199+
200+
response = await run_in_threadpool(
201+
lambda: store.retrieve_online_documents_v2(**read_params) # type: ignore
202+
)
203+
204+
# Convert the Protobuf object to JSON and return it
205+
response_dict = await run_in_threadpool(
206+
MessageToDict,
207+
response.proto,
208+
preserving_proto_field_name=True,
209+
float_precision=18,
210+
)
211+
return response_dict
212+
180213
@app.post("/push", dependencies=[Depends(inject_user_details)])
181214
async def push(request: PushFeaturesRequest) -> None:
182215
df = pd.DataFrame(request.df)

0 commit comments

Comments
 (0)