BrejBala commited on
Commit
58d4ba0
Β·
verified Β·
1 Parent(s): 7117274

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +173 -1
README.md CHANGED
@@ -9,4 +9,176 @@ pinned: false
9
  license: mit
10
  ---
11
 
12
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
  license: mit
10
  ---
11
 
12
+ # 🧠 RAG Agent Workbench β€” Backend API (FastAPI on Docker Spaces)
13
+
14
+ A production-style Retrieval-Augmented Generation (RAG) backend deployed on **Hugging Face Spaces (Docker)**.
15
+
16
+ - **Vector DB:** Pinecone (serverless)
17
+ - **LLM:** Groq (OpenAI-compatible)
18
+ - **Web fallback:** Tavily (optional)
19
+ - **Orchestration:** LangGraph / LangChain
20
+ - **Observability:** LangSmith tracing (optional)
21
+ - **Security:** API Key required (Swagger + OpenAPI + endpoints)
22
+
23
+ > This Space is public, but the API is protected via `X-API-Key` so it can’t be used without your key.
24
+
25
+ ---
26
+
27
+ ## βœ… API Endpoints
28
+
29
+ Typical endpoints you can expect:
30
+
31
+ - `GET /health` β€” health check
32
+ - `POST /chat` β€” RAG chat (optionally web fallback)
33
+ - `POST /search` β€” semantic retrieval
34
+ - `POST /documents/upload-text` β€” upload raw text for indexing
35
+ - `POST /ingest/wiki` β€” ingest from Wikipedia REST API
36
+ - `POST /ingest/arxiv` β€” ingest from arXiv API
37
+ - `POST /ingest/openalex` β€” ingest from OpenAlex API
38
+ - `GET /documents/stats` β€” namespace/vector stats
39
+ - `GET /metrics` β€” in-app metrics (latency, counts, cache hits, etc.)
40
+
41
+ Swagger/OpenAPI:
42
+ - `/docs` (Swagger UI)
43
+ - `/openapi.json`
44
+
45
+ > If API key protection is enabled, `/docs` and `/openapi.json` are also protected.
46
+
47
+ ---
48
+
49
+ ## πŸ” Authentication (API Key)
50
+
51
+ All protected endpoints require:
52
+
53
+ - Header: `X-API-Key: <YOUR_API_KEY>`
54
+
55
+ If `API_KEY` is set in Space secrets, anonymous access is blocked.
56
+
57
+ ---
58
+
59
+ ## βš™οΈ Configuration (Space Secrets & Variables)
60
+
61
+ Hugging Face Spaces lets you set **Secrets/Variables in Space Settings**; inside the container they are available as environment variables. :contentReference[oaicite:1]{index=1}
62
+
63
+ Go to:
64
+ **Space β†’ Settings β†’ Variables and secrets**
65
+
66
+ ### Required (Pinecone)
67
+ - `PINECONE_API_KEY` (Secret)
68
+ - `PINECONE_HOST` (Secret or Variable)
69
+ - `PINECONE_INDEX_NAME` (Variable) β€” e.g. `rag-agent-workbench`
70
+ - `PINECONE_NAMESPACE` (Variable) β€” e.g. `dev`
71
+ - `PINECONE_TEXT_FIELD` (Variable) β€” `content` (for integrated embedding field mapping)
72
+
73
+ ### Required (Groq)
74
+ Groq supports OpenAI-compatible clients via `base_url = https://api.groq.com/openai/v1`. :contentReference[oaicite:2]{index=2}
75
+
76
+ - `GROQ_API_KEY` (Secret)
77
+ - `GROQ_BASE_URL` (Variable) β€” `https://api.groq.com/openai/v1`
78
+ - `GROQ_MODEL` (Variable) β€” choose your Groq model (e.g., `llama-3.1-8b-instant`)
79
+
80
+ ### Optional (Tavily web fallback)
81
+ - `TAVILY_API_KEY` (Secret)
82
+
83
+ ### Optional (LangSmith tracing)
84
+ LangSmith commonly uses environment variables like `LANGCHAIN_API_KEY` and `LANGCHAIN_TRACING_V2=true`; project can be set via `LANGCHAIN_PROJECT` (or `LANGSMITH_PROJECT` depending on SDK usage). :contentReference[oaicite:3]{index=3}
85
+
86
+ - `LANGCHAIN_TRACING_V2` (Variable) β€” `true`
87
+ - `LANGCHAIN_API_KEY` (Secret)
88
+ - `LANGCHAIN_PROJECT` (Variable) β€” e.g. `rag-agent-workbench`
89
+
90
+ ### Strongly recommended (Security)
91
+ - `API_KEY` (Secret) β€” required to call API endpoints
92
+
93
+ ### Optional (Ops toggles)
94
+ - `LOG_LEVEL` β€” `INFO`
95
+ - `CACHE_ENABLED` β€” `true/false`
96
+ - `RATE_LIMIT_ENABLED` β€” `true/false`
97
+ - `ALLOWED_ORIGINS` β€” comma-separated list (if you need strict CORS)
98
+
99
+ > Any change to Space secrets/variables triggers a restart. :contentReference[oaicite:4]{index=4}
100
+
101
+ ---
102
+
103
+ ## πŸš€ How to Test This Space
104
+
105
+ Replace:
106
+ - `SPACE_URL = https://<your-space-subdomain>.hf.space`
107
+ - `KEY = your API key`
108
+
109
+ ### 1) Health
110
+ curl -i "$SPACE_URL/health"
111
+
112
+ ### 2) OpenAPI / Swagger (requires key if protected)
113
+ curl -i "$SPACE_URL/openapi.json" -H "X-API-Key: $KEY"
114
+
115
+ ### 3) Search
116
+ curl -X POST "$SPACE_URL/search" \
117
+ -H "Content-Type: application/json" \
118
+ -H "X-API-Key: $KEY" \
119
+ -d '{"query":"What is RAG?","top_k":5,"namespace":"dev"}'
120
+
121
+ ### 4) Chat
122
+ curl -X POST "$SPACE_URL/chat" \
123
+ -H "Content-Type: application/json" \
124
+ -H "X-API-Key: $KEY" \
125
+ -d '{"query":"Explain RAG in 5 bullets.","namespace":"dev","top_k":5,"use_web_fallback":false}'
126
+
127
+ ### 5) Upload text document
128
+ curl -X POST "$SPACE_URL/documents/upload-text" \
129
+ -H "Content-Type: application/json" \
130
+ -H "X-API-Key: $KEY" \
131
+ -d '{
132
+ "title":"Demo doc",
133
+ "source":"space-readme",
134
+ "namespace":"dev",
135
+ "text":"RAG = retrieval augmented generation ...",
136
+ "metadata":{"tag":"demo"}
137
+ }'
138
+
139
+ ---
140
+
141
+ ## 🐳 Local Docker Run (same image behavior as Spaces)
142
+
143
+ Docker Spaces is configured via YAML front-matter (`sdk: docker`, `app_port`) and expects the app to listen on the configured port (commonly 7860). :contentReference[oaicite:5]{index=5}
144
+
145
+ Build:
146
+ docker build -t rag-agent-workbench-api:local .
147
+
148
+ Run:
149
+ docker run --rm -p 7860:7860 \
150
+ -e API_KEY="your_key" \
151
+ -e PINECONE_API_KEY="..." \
152
+ -e PINECONE_HOST="..." \
153
+ -e PINECONE_INDEX_NAME="rag-agent-workbench" \
154
+ -e PINECONE_NAMESPACE="dev" \
155
+ -e PINECONE_TEXT_FIELD="content" \
156
+ -e GROQ_API_KEY="..." \
157
+ -e GROQ_BASE_URL="https://api.groq.com/openai/v1" \
158
+ -e GROQ_MODEL="llama-3.1-8b-instant" \
159
+ rag-agent-workbench-api:local
160
+
161
+ Then open:
162
+ - http://127.0.0.1:7860/health
163
+ - http://127.0.0.1:7860/docs (add X-API-Key if protected)
164
+
165
+ ---
166
+
167
+ ## 🧯 Troubleshooting
168
+
169
+ ### Space starts but endpoints 404 / not reachable
170
+ - Confirm `app_port: 7860` in YAML and container listens on that port. :contentReference[oaicite:6]{index=6}
171
+
172
+ ### 403 on everything
173
+ - You enabled `API_KEY` but forgot to send `X-API-Key` header.
174
+
175
+ ### Web fallback not working
176
+ - Ensure `TAVILY_API_KEY` is set in Space secrets.
177
+
178
+ ### LangSmith traces missing
179
+ - Ensure `LANGCHAIN_TRACING_V2=true` and `LANGCHAIN_API_KEY` are set. :contentReference[oaicite:7]{index=7}
180
+
181
+ ---
182
+
183
+ ## πŸ“„ License
184
+ MIT recommended for open-source portfolios