Skip to content

Commit 0173033

Browse files
authored
feat: Add feast rag retriver functionality (feast-dev#5405)
Add feast rag retriver functionality Signed-off-by: Fiona Waters <[email protected]>
1 parent ebd67d1 commit 0173033

33 files changed

+6574
-4126
lines changed

.github/workflows/unit_tests.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,6 @@ jobs:
3030
uses: astral-sh/setup-uv@v5
3131
with:
3232
enable-cache: true
33-
- name: Install torch (platform-specific)
34-
run: |
35-
if [[ "$RUNNER_OS" == "Linux" ]]; then
36-
pip install torch torchvision \
37-
--index-url https://download.pytorch.org/whl/cpu
38-
fi
3933
- name: Install dependencies
4034
run: make install-python-dependencies-ci
4135
- name: Test Python

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ install-python-dependencies-minimal: ## Install minimal Python dependencies usin
8181
# Used in github actions/ci
8282
# formerly install-python-ci-dependencies-uv
8383
install-python-dependencies-ci: ## Install Python CI dependencies in system environment using uv
84+
# Install CPU-only torch first to prevent CUDA dependency issues
85+
pip uninstall torch torchvision -y || true
86+
pip install torch torchvision --index-url https://download.pytorch.org/whl/cpu --force-reinstall
8487
uv pip sync --system sdk/python/requirements/py$(PYTHON_VERSION)-ci-requirements.txt
8588
uv pip install --system --no-deps -e .
8689

examples/rag-retriever/README.md

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# End-to-end RAG example using Feast and Milvus.
2+
3+
## Introduction
4+
This example notebook provides a step-by-step demonstration of building and using a RAG system with Feast Feature Store and the custom FeastRagRetriever. The notebook walks through:
5+
6+
1. Data Preparation
7+
- Loads a subset of the Wikipedia DPR dataset (1% of training data)
8+
- Implements text chunking with configurable chunk size and overlap
9+
- Processes text into manageable passages with unique IDs
10+
11+
2. Embedding Generation
12+
- Uses `all-MiniLM-L6-v2` sentence transformer model
13+
- Generates 384-dimensional embeddings for text passages
14+
- Demonstrates batch processing with GPU support
15+
16+
3. Feature Store Setup
17+
- Creates a Parquet file as the historical data source
18+
- Configures Feast with the feature repository
19+
- Demonstrates writing embeddings from data source to Milvus online store which can be used for model training later
20+
21+
4. RAG System Implementation
22+
- **Embedding Model**: `all-MiniLM-L6-v2` (configurable)
23+
- **Generator Model**: `granite-3.2-2b-instruct` (configurable)
24+
- **Vector Store**: Custom implementation with Feast integration
25+
- **Retriever**: Custom implementation extending HuggingFace's RagRetriever
26+
27+
5. Query Demonstration
28+
- Perform inference with retrieved context
29+
30+
## Requirements
31+
- A Kubernetes cluster with:
32+
- GPU nodes available (for model inference)
33+
- At least 200GB of storage
34+
- A standalone Milvus deployment. See example [here](https://github.com/milvus-io/milvus-helm/tree/master/charts/milvus).
35+
36+
## Running the example
37+
Clone this repository: https://github.com/feast-dev/feast.git
38+
Navigate to the examples/rag-retriever directory. Here you will find the following files:
39+
40+
* **feature_repo/feature_store.yaml**
41+
This is the core configuration file for the RAG project's feature store, configuring a Milvus online store on a local provider.
42+
* In order to configure Milvus you should:
43+
- Update `feature_store.yaml` with your Milvus connection details:
44+
- host
45+
- port (default: 19530)
46+
- credentials (if required)
47+
48+
* **__feature_repo/ragproject_repo.py__**
49+
This is the Feast feature repository configuration that defines the schema and data source for Wikipedia passage embeddings.
50+
51+
* **__rag_feast.ipynb__**
52+
This is a notebook demonstrating the implementation of a RAG system using Feast feature store. The notebook provides:
53+
54+
- A complete end-to-end example of building a RAG system with:
55+
- Data preparation using the Wiki DPR dataset
56+
- Text chunking and preprocessing
57+
- Vector embedding generation using sentence-transformers
58+
- Integration with Milvus vector store
59+
- Inference utilising a custom RagRetriever: FeastRagRetriever
60+
- Uses `all-MiniLM-L6-v2` for generating embeddings
61+
- Implements `granite-3.2-2b-instruct` as the generator model
62+
63+
Open `rag_feast.ipynb` and follow the steps in the notebook to run the example.
64+
65+
## FeastRagRetriver Low Level Design
66+
67+
<img src="images/FeastRagRetriever.png" width="800" height="450" alt="Low level design for feast rag retriever">
68+
69+
## Helpful Information
70+
- Ensure your Milvus instance is properly configured and running
71+
- Vector dimensions and similarity metrics can be adjusted in the feature store configuration
72+
- The example uses Wikipedia data, but the system can be adapted for other datasets
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
project: ragproject
2+
provider: local
3+
registry: data/registry.db
4+
online_store:
5+
type: milvus
6+
host: # Insert Milvus route host
7+
username: # Insert Milvus username if required
8+
password: # Insert Milvus password if required
9+
port: 19530
10+
vector_enabled: true
11+
embedding_dim: 384
12+
index_type: FLAT
13+
metric_type: COSINE
14+
offline_store:
15+
type: file
16+
entity_key_serialization_version: 3
17+
auth:
18+
type: no_auth
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
from datetime import timedelta
2+
3+
from feast import Entity, FeatureView, Field, FileSource, ValueType
4+
from feast.data_format import ParquetFormat
5+
from feast.types import Array, Float32, String
6+
7+
# Define your entity (primary key for feature lookup)
8+
wiki_passage = Entity(
9+
name="passage_id",
10+
join_keys=["passage_id"],
11+
value_type=ValueType.STRING,
12+
description="Unique ID of a Wikipedia passage",
13+
)
14+
15+
parquet_file_path = "data/wiki_dpr.parquet"
16+
17+
# Define offline source
18+
wiki_dpr_source = FileSource(
19+
name="wiki_dpr_source",
20+
file_format=ParquetFormat(),
21+
path=parquet_file_path,
22+
timestamp_field="event_timestamp",
23+
)
24+
25+
# Define the feature view for the Wikipedia passage content
26+
wiki_passage_feature_view = FeatureView(
27+
name="wiki_passages",
28+
entities=[wiki_passage],
29+
ttl=timedelta(days=1),
30+
schema=[
31+
Field(
32+
name="passage_text",
33+
dtype=String,
34+
description="Content of the Wikipedia passage",
35+
),
36+
Field(
37+
name="embedding",
38+
dtype=Array(Float32),
39+
description="vectors",
40+
vector_index=True,
41+
vector_length=384,
42+
vector_search_metric="COSINE",
43+
),
44+
],
45+
online=True,
46+
source=wiki_dpr_source,
47+
description="Content features of Wikipedia passages",
48+
)
83.5 KB
Loading

0 commit comments

Comments
 (0)