|
1 | | -# Feast Quickstart |
2 | | -If you haven't already, check out the quickstart guide on Feast's website (http://docs.feast.dev/quickstart), which |
3 | | -uses this repo. A quick view of what's in this repository's `feature_repo/` directory: |
4 | | - |
5 | | -* `data/` contains raw demo parquet data |
6 | | -* `feature_repo/example_repo.py` contains demo feature definitions |
7 | | -* `feature_repo/feature_store.yaml` contains a demo setup configuring where data sources are |
8 | | -* `feature_repo/test_workflow.py` showcases how to run all key Feast commands, including defining, retrieving, and pushing features. |
9 | | - |
10 | | -You can run the overall workflow with `python test_workflow.py`. |
11 | | - |
12 | | -## To move from this into a more production ready workflow: |
13 | | -> See more details in [Running Feast in production](https://docs.feast.dev/how-to-guides/running-feast-in-production) |
14 | | -
|
15 | | -1. First: you should start with a different Feast template, which delegates to a more scalable offline store. |
16 | | - - For example, running `feast init -t gcp` |
17 | | - or `feast init -t aws` or `feast init -t snowflake`. |
18 | | - - You can see your options if you run `feast init --help`. |
19 | | -2. `feature_store.yaml` points to a local file as a registry. You'll want to setup a remote file (e.g. in S3/GCS) or a |
20 | | -SQL registry. See [registry docs](https://docs.feast.dev/getting-started/concepts/registry) for more details. |
21 | | -3. This example uses a file [offline store](https://docs.feast.dev/getting-started/components/offline-store) |
22 | | - to generate training data. It does not scale. We recommend instead using a data warehouse such as BigQuery, |
23 | | - Snowflake, Redshift. There is experimental support for Spark as well. |
24 | | -4. Setup CI/CD + dev vs staging vs prod environments to automatically update the registry as you change Feast feature definitions. See [docs](https://docs.feast.dev/how-to-guides/running-feast-in-production#1.-automatically-deploying-changes-to-your-feature-definitions). |
25 | | -5. (optional) Regularly scheduled materialization to power low latency feature retrieval (e.g. via Airflow). See [Batch data ingestion](https://docs.feast.dev/getting-started/concepts/data-ingestion#batch-data-ingestion) |
26 | | -for more details. |
27 | | -6. (optional) Deploy feature server instances with `feast serve` to expose endpoints to retrieve online features. |
28 | | - - See [Python feature server](https://docs.feast.dev/reference/feature-servers/python-feature-server) for details. |
29 | | - - Use cases can also directly call the Feast client to fetch features as per [Feature retrieval](https://docs.feast.dev/getting-started/concepts/feature-retrieval) |
| 1 | +# 🚀 Quickstart: Retrieval-Augmented Generation (RAG) using Feast and Large Language Models (LLMs) |
| 2 | + |
| 3 | +This project demonstrates how to use **Feast** to power a **Retrieval-Augmented Generation (RAG)** application. |
| 4 | +The RAG architecture combines retrieval of documents (using vector search) with contextual reasoning through a |
| 5 | +**Large Language Model (LLM)** to answer user questions accurately using structured and unstructured data. |
| 6 | + |
| 7 | +## 💡 Why Use Feast for RAG? |
| 8 | + |
| 9 | +- **Online retrieval of features:** Ensure real-time access to precomputed document embeddings and other structured data. |
| 10 | +- **Vector search:** Leverage Feast’s integration with vector databases like **Milvus** to find relevant documents based on similarity. |
| 11 | +- **Structured and unstructured context:** Retrieve both embeddings and traditional features, injecting richer context into LLM prompts. |
| 12 | +- **Versioning and reusability:** Collaborate across teams with discoverable, versioned data pipelines. |
| 13 | + |
| 14 | +--- |
| 15 | + |
| 16 | +## 📂 Project Structure |
| 17 | + |
| 18 | +- **`data/`**: Contains the demo data, including Wikipedia summaries of cities with sentence embeddings stored in a Parquet file. |
| 19 | +- **`example_repo.py`**: Defines the feature views and entity configurations for Feast. |
| 20 | +- **`feature_store.yaml`**: Configures the offline and online stores (using local files and Milvus Lite in this demo). |
| 21 | +- **`test_workflow.py`**: Demonstrates key Feast commands to define, retrieve, and push features. |
| 22 | + |
| 23 | +--- |
| 24 | + |
| 25 | +## 🛠️ Setup |
| 26 | + |
| 27 | +1. **Install the necessary packages**: |
| 28 | + ```bash |
| 29 | + pip install feast torch transformers openai |
| 30 | + ``` |
| 31 | +2. Initialize and inspect the feature store: |
| 32 | + |
| 33 | + ```bash |
| 34 | + feast apply |
| 35 | + ``` |
| 36 | + |
| 37 | +3. Materialize features into the online store: |
| 38 | + |
| 39 | + ```bash |
| 40 | + python -c "from datetime import datetime; from feast import FeatureStore; store = FeatureStore(repo_path='.')" |
| 41 | + python -c "store.materialize_incremental(datetime.utcnow())" |
| 42 | + ``` |
| 43 | +4. Run a query: |
| 44 | + |
| 45 | +- Prepare your question: |
| 46 | +`question = "Which city has the largest population in New York?"` |
| 47 | +- Embed the question using sentence-transformers/all-MiniLM-L6-v2. |
| 48 | +- Retrieve the top K most relevant documents using Milvus vector search. |
| 49 | +- Pass the retrieved context to the OpenAI model for conversational output. |
| 50 | + |
| 51 | +## 🛠️ Key Commands for Data Scientists |
| 52 | +- Apply feature definitions: |
| 53 | + |
| 54 | +```bash |
| 55 | +feast apply |
| 56 | +``` |
| 57 | + |
| 58 | +- Materialize features to the online store: |
| 59 | +```python |
| 60 | +store.write_to_online_store(feature_view_name='city_embeddings', df=df) |
| 61 | +``` |
| 62 | + |
| 63 | +-Inspect retrieved features using Python: |
| 64 | +```python |
| 65 | +context_data = store.retrieve_online_documents_v2( |
| 66 | + features=[ |
| 67 | + "city_embeddings:vector", |
| 68 | + "city_embeddings:item_id", |
| 69 | + "city_embeddings:state", |
| 70 | + "city_embeddings:sentence_chunks", |
| 71 | + "city_embeddings:wiki_summary", |
| 72 | + ], |
| 73 | + query=query, |
| 74 | + top_k=3, |
| 75 | + distance_metric='COSINE', |
| 76 | +).to_df() |
| 77 | +display(context_data) |
| 78 | +``` |
| 79 | + |
| 80 | +## 🔑 Explanation of Core Concepts |
| 81 | +Feature View: Defines the schema of features and how they are retrieved from the offline store. |
| 82 | +Entity: Represents primary keys like item_id for indexing and lookup. |
| 83 | +Vector Search: Uses Milvus Lite to retrieve document embeddings based on cosine similarity. |
| 84 | +LLM Context Injection: Retrieved documents are formatted and injected into the LLM prompt to provide grounded responses. |
0 commit comments