-
Notifications
You must be signed in to change notification settings - Fork 1k
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
feat: Elasticsearch vector database #4188
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
e33aa20
add elasticsearch as online store
HaoXuAI 091e838
add elasticsearch as online store
HaoXuAI de668fb
format
HaoXuAI d3619f6
format
HaoXuAI 7a09138
format
HaoXuAI f33e769
format
HaoXuAI 9153983
fix search
HaoXuAI 5a212ba
format
HaoXuAI 0689021
format
HaoXuAI 1dc08ba
format
HaoXuAI c689a04
format
HaoXuAI 999cba1
add test
HaoXuAI e93956d
add test
HaoXuAI 369cfd4
fix e2e test
HaoXuAI ff96123
format
HaoXuAI d76bce6
fix test
HaoXuAI 48a3e75
Merge branch 'master' into hao-xu-elasticsearch-vector
HaoXuAI bdb973e
fix test
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
There are no files selected for viewing
This file contains 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 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 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,125 @@ | ||
# ElasticSearch online store (contrib) | ||
|
||
## Description | ||
|
||
The ElasticSearch online store provides support for materializing tabular feature values, as well as embedding feature vectors, into an ElasticSearch index for serving online features. \ | ||
The embedding feature vectors are stored as dense vectors, and can be used for similarity search. More information on dense vectors can be found [here](https://www.elastic.co/guide/en/elasticsearch/reference/current/dense-vector.html). | ||
|
||
## Getting started | ||
In order to use this online store, you'll need to run `pip install 'feast[elasticsearch]'`. You can get started by then running `feast init -t elasticsearch`. | ||
|
||
## Example | ||
|
||
{% code title="feature_store.yaml" %} | ||
```yaml | ||
project: my_feature_repo | ||
registry: data/registry.db | ||
provider: local | ||
online_store: | ||
type: elasticsearch | ||
host: ES_HOST | ||
port: ES_PORT | ||
user: ES_USERNAME | ||
password: ES_PASSWORD | ||
vector_len: 512 | ||
write_batch_size: 1000 | ||
``` | ||
{% endcode %} | ||
|
||
The full set of configuration options is available in [ElasticsearchOnlineStoreConfig](https://rtd.feast.dev/en/master/#feast.infra.online_stores.contrib.elasticsearch.ElasticsearchOnlineStoreConfig). | ||
|
||
## Functionality Matrix | ||
|
||
|
||
| | Postgres | | ||
| :-------------------------------------------------------- | :------- | | ||
| write feature values to the online store | yes | | ||
| read feature values from the online store | yes | | ||
| update infrastructure (e.g. tables) in the online store | yes | | ||
| teardown infrastructure (e.g. tables) in the online store | yes | | ||
| generate a plan of infrastructure changes | no | | ||
| support for on-demand transforms | yes | | ||
| readable by Python SDK | yes | | ||
| readable by Java | no | | ||
| readable by Go | no | | ||
| support for entityless feature views | yes | | ||
| support for concurrent writing to the same key | no | | ||
| support for ttl (time to live) at retrieval | no | | ||
| support for deleting expired data | no | | ||
| collocated by feature view | yes | | ||
| collocated by feature service | no | | ||
| collocated by entity key | no | | ||
|
||
To compare this set of functionality against other online stores, please see the full [functionality matrix](overview.md#functionality-matrix). | ||
|
||
## Retrieving online document vectors | ||
|
||
The ElasticSearch online store supports retrieving document vectors for a given list of entity keys. The document vectors are returned as a dictionary where the key is the entity key and the value is the document vector. The document vector is a dense vector of floats. | ||
|
||
{% code title="python" %} | ||
```python | ||
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( | ||
feature="my_feature", | ||
query=query_vector, | ||
top_k=top_k | ||
) | ||
``` | ||
{% endcode %} | ||
|
||
## Indexing | ||
Currently, the indexing mapping in the ElasticSearch online store is configured as: | ||
|
||
{% code title="indexing_mapping" %} | ||
```json | ||
"properties": { | ||
"entity_key": {"type": "binary"}, | ||
"feature_name": {"type": "keyword"}, | ||
"feature_value": {"type": "binary"}, | ||
"timestamp": {"type": "date"}, | ||
"created_ts": {"type": "date"}, | ||
"vector_value": { | ||
"type": "dense_vector", | ||
"dims": config.online_store.vector_len, | ||
"index": "true", | ||
"similarity": config.online_store.similarity, | ||
}, | ||
} | ||
``` | ||
{% endcode %} | ||
And the online_read API mapping is configured as: | ||
|
||
{% code title="online_read_mapping" %} | ||
```json | ||
"query": { | ||
"bool": { | ||
"must": [ | ||
{"terms": {"entity_key": entity_keys}}, | ||
{"terms": {"feature_name": requested_features}}, | ||
] | ||
} | ||
}, | ||
``` | ||
{% endcode %} | ||
|
||
And the similarity search API mapping is configured as: | ||
|
||
{% code title="similarity_search_mapping" %} | ||
```json | ||
{ | ||
"field": "vector_value", | ||
"query_vector": embedding_vector, | ||
"k": top_k, | ||
} | ||
``` | ||
{% endcode %} | ||
|
||
These APIs are subject to change in future versions of Feast to improve performance and usability. |
This file contains 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.
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.
have to make it optional as
elasticsearch
doesn't allow specifying the metric in the online API. Instead, it has to update the index.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.
Makes sense can we add some explicit tests for this to highlight the behavior? Also this is awesome.