Elasticsearch
Last updated
Was this helpful?
Was this helpful?
from feast import FeatureStore
feature_store = FeatureStore(repo_path="feature_store.yaml")
query_vector = [1.0, 2.0, 3.0, 4.0, 5.0]
top_k = 5
# Retrieve the top k closest features to the query vector
feature_values = feature_store.retrieve_online_documents_v2(
features=["my_feature"],
query=query_vector,
top_k=top_k,
){
"dynamic_templates": [
{
"feature_objects": {
"match_mapping_type": "object",
"match": "*",
"mapping": {
"type": "object",
"properties": {
"feature_value": {"type": "binary"},
"value_text": {"type": "text"},
"vector_value": {
"type": "dense_vector",
"dims": vector_field_length,
"index": True,
"similarity": config.online_store.similarity,
},
},
},
}
}
],
"properties": {
"entity_key": {"type": "keyword"},
"timestamp": {"type": "date"},
"created_ts": {"type": "date"},
},
}"query": {
"bool": {
"must": [
{"terms": {"entity_key": entity_keys}},
{"terms": {"feature_name": requested_features}},
]
}
},{
"field": "vector_value",
"query_vector": embedding_vector,
"k": top_k,
}