File size: 3,460 Bytes
5fd4bb2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
# Environment Variables Setup

This document describes the environment variables needed to run the RAG system.

## Required Variables

### HF_TOKEN (Required)

Your Hugging Face API token for accessing the Inference API.

**How to get it:**
1. Go to [https://huggingface.co/settings/tokens](https://huggingface.co/settings/tokens)
2. Click "New token"
3. Give it a name (e.g., "RAG System")
4. Select `read` permissions
5. Click "Generate"
6. Copy the token (starts with `hf_`)

**Set it:**

```bash
# Linux/Mac
export HF_TOKEN=hf_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

# Windows (PowerShell)
$env:HF_TOKEN="hf_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"

# Windows (CMD)
set HF_TOKEN=hf_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
```

**For Hugging Face Spaces:**
- Go to Space Settings → Repository secrets
- Add secret: Name=`HF_TOKEN`, Value=your token

## Optional Variables

### HF_MODEL

The Hugging Face model to use for text generation.

**Default:** `meta-llama/Llama-3.2-3B-Instruct`

**Other options:**
- `mistralai/Mistral-7B-Instruct-v0.2`
- `meta-llama/Meta-Llama-3-8B-Instruct`

```bash
export HF_MODEL=meta-llama/Llama-3.2-3B-Instruct
```

### EMBEDDING_MODEL

The sentence transformer model for embeddings (runs locally).

**Default:** `all-MiniLM-L6-v2`

```bash
export EMBEDDING_MODEL=all-MiniLM-L6-v2
```

### CHROMA_PERSIST_DIR

Directory for ChromaDB vector database storage.

**Default:** `./chroma_db`

```bash
export CHROMA_PERSIST_DIR=./chroma_db
```

### DOCUMENTS_DIR

Directory containing source documents.

**Default:** `./documents`

```bash
export DOCUMENTS_DIR=./documents
```

### PROCESSED_DOCS_DIR

Directory for processed markdown documents.

**Default:** `./processed_docs`

```bash
export PROCESSED_DOCS_DIR=./processed_docs
```

### DEFAULT_N_RESULTS

Number of context chunks to retrieve for each query.

**Default:** `5`

```bash
export DEFAULT_N_RESULTS=5
```

### SIMILARITY_THRESHOLD

Minimum similarity score for retrieved chunks.

**Default:** `0.5`

```bash
export SIMILARITY_THRESHOLD=0.5
```

### CHUNK_SIZE

Size of text chunks for processing.

**Default:** `1000`

```bash
export CHUNK_SIZE=1000
```

### CHUNK_OVERLAP

Overlap between consecutive chunks.

**Default:** `200`

```bash
export CHUNK_OVERLAP=200
```

### GRADIO_SHARE

Whether to create a public Gradio share link.

**Default:** `False` (set to `True` for 72-hour public link)

```bash
export GRADIO_SHARE=True
```

### GRADIO_SERVER_PORT

Port for the Gradio server.

**Default:** `7860`

```bash
export GRADIO_SERVER_PORT=7860
```

## Complete Example

Create a `.env` file in the project root:

```bash
# Required
HF_TOKEN=hf_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

# Optional (uncomment to override defaults)
# HF_MODEL=meta-llama/Llama-3.2-3B-Instruct
# EMBEDDING_MODEL=all-MiniLM-L6-v2
# CHROMA_PERSIST_DIR=./chroma_db
# DOCUMENTS_DIR=./documents
# PROCESSED_DOCS_DIR=./processed_docs
# DEFAULT_N_RESULTS=5
# SIMILARITY_THRESHOLD=0.5
# CHUNK_SIZE=1000
# CHUNK_OVERLAP=200
# GRADIO_SHARE=False
# GRADIO_SERVER_PORT=7860
```

Then load it before running:

```bash
# Using python-dotenv (recommended)
pip install python-dotenv
# Add to your script: from dotenv import load_dotenv; load_dotenv()

# Or manually source it
source .env  # Linux/Mac
```

## Verification

To verify your environment is set up correctly:

```bash
python -c "import os; print('HF_TOKEN:', 'SET' if os.getenv('HF_TOKEN') else 'NOT SET')"
```

Should output: `HF_TOKEN: SET`