opencode-skills-collection 3.1.9 → 3.1.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bundled-skills/.antigravity-install-manifest.json +8 -1
- package/bundled-skills/browser-testing-with-devtools/SKILL.md +334 -0
- package/bundled-skills/docs/integrations/jetski-cortex.md +3 -3
- package/bundled-skills/docs/integrations/jetski-gemini-loader/README.md +1 -1
- package/bundled-skills/docs/maintainers/repo-growth-seo.md +3 -3
- package/bundled-skills/docs/maintainers/skills-update-guide.md +1 -1
- package/bundled-skills/docs/sources/sources.md +4 -0
- package/bundled-skills/docs/users/bundles.md +1 -1
- package/bundled-skills/docs/users/claude-code-skills.md +1 -1
- package/bundled-skills/docs/users/gemini-cli-skills.md +1 -1
- package/bundled-skills/docs/users/getting-started.md +1 -1
- package/bundled-skills/docs/users/kiro-integration.md +1 -1
- package/bundled-skills/docs/users/usage.md +4 -4
- package/bundled-skills/docs/users/visual-guide.md +4 -4
- package/bundled-skills/drizzle-migration-conflict/SKILL.md +179 -0
- package/bundled-skills/drizzle-migration-conflict/references/ci-policy.md +87 -0
- package/bundled-skills/drizzle-migration-conflict/references/conflict-resolution.md +163 -0
- package/bundled-skills/drizzle-migration-conflict/references/report-template.md +69 -0
- package/bundled-skills/drizzle-migration-conflict/references/sources.md +51 -0
- package/bundled-skills/drizzle-migration-conflict/scripts/check_drizzle_migrations.py +721 -0
- package/bundled-skills/frontend-lighthouse/SKILL.md +348 -0
- package/bundled-skills/pre-release-review/SKILL.md +198 -0
- package/bundled-skills/pre-release-review/references/checklist.md +104 -0
- package/bundled-skills/pre-release-review/references/report-template.md +91 -0
- package/bundled-skills/re-create/SKILL.md +251 -0
- package/bundled-skills/weaviate/SKILL.md +132 -0
- package/bundled-skills/weaviate/references/ask.md +36 -0
- package/bundled-skills/weaviate/references/create_collection.md +152 -0
- package/bundled-skills/weaviate/references/environment_requirements.md +34 -0
- package/bundled-skills/weaviate/references/example_data.md +24 -0
- package/bundled-skills/weaviate/references/explore_collection.md +50 -0
- package/bundled-skills/weaviate/references/fetch_filter.md +88 -0
- package/bundled-skills/weaviate/references/get_collection.md +32 -0
- package/bundled-skills/weaviate/references/hybrid_search.md +47 -0
- package/bundled-skills/weaviate/references/import_data.md +160 -0
- package/bundled-skills/weaviate/references/keyword_search.md +38 -0
- package/bundled-skills/weaviate/references/list_collections.md +31 -0
- package/bundled-skills/weaviate/references/query_search.md +38 -0
- package/bundled-skills/weaviate/references/semantic_search.md +46 -0
- package/bundled-skills/weaviate/scripts/ask.py +106 -0
- package/bundled-skills/weaviate/scripts/create_collection.py +359 -0
- package/bundled-skills/weaviate/scripts/example_data.py +945 -0
- package/bundled-skills/weaviate/scripts/explore_collection.py +295 -0
- package/bundled-skills/weaviate/scripts/fetch_filter.py +261 -0
- package/bundled-skills/weaviate/scripts/get_collection.py +122 -0
- package/bundled-skills/weaviate/scripts/hybrid_search.py +157 -0
- package/bundled-skills/weaviate/scripts/import.py +701 -0
- package/bundled-skills/weaviate/scripts/keyword_search.py +142 -0
- package/bundled-skills/weaviate/scripts/list_collections.py +77 -0
- package/bundled-skills/weaviate/scripts/query_search.py +135 -0
- package/bundled-skills/weaviate/scripts/semantic_search.py +139 -0
- package/bundled-skills/weaviate/scripts/weaviate_conn.py +231 -0
- package/bundled-skills/weaviate-cookbooks/SKILL.md +67 -0
- package/bundled-skills/weaviate-cookbooks/references/advanced_rag.md +274 -0
- package/bundled-skills/weaviate-cookbooks/references/agentic_rag.md +360 -0
- package/bundled-skills/weaviate-cookbooks/references/async_client.md +428 -0
- package/bundled-skills/weaviate-cookbooks/references/basic_agent.md +270 -0
- package/bundled-skills/weaviate-cookbooks/references/basic_rag.md +219 -0
- package/bundled-skills/weaviate-cookbooks/references/data_explorer.md +336 -0
- package/bundled-skills/weaviate-cookbooks/references/environment_requirements.md +78 -0
- package/bundled-skills/weaviate-cookbooks/references/frontend_interface.md +104 -0
- package/bundled-skills/weaviate-cookbooks/references/pdf_multimodal_rag.md +635 -0
- package/bundled-skills/weaviate-cookbooks/references/project_setup.md +75 -0
- package/bundled-skills/weaviate-cookbooks/references/query_agent_chatbot.md +163 -0
- package/package.json +1 -1
- package/skills_index.json +156 -0
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
# Basic RAG Cookbook
|
|
2
|
+
|
|
3
|
+
Build basic RAG functionality with Weaviate.
|
|
4
|
+
For advanced strategies, [see here](./advanced_rag.md).
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
Docs to reference if needed:
|
|
8
|
+
- Search patterns and basics in Weaviate: https://docs.weaviate.io/weaviate/search/basics
|
|
9
|
+
- Filters in Weaviate: https://docs.weaviate.io/weaviate/search/filters
|
|
10
|
+
- Vector search: https://docs.weaviate.io/weaviate/search/similarity
|
|
11
|
+
- Keyword search: https://docs.weaviate.io/weaviate/search/bm25
|
|
12
|
+
- Hybrid search: https://docs.weaviate.io/weaviate/search/hybrid
|
|
13
|
+
- Image search: https://docs.weaviate.io/weaviate/search/image
|
|
14
|
+
|
|
15
|
+
## Core Rules
|
|
16
|
+
|
|
17
|
+
- Use a virtual environment via `venv`
|
|
18
|
+
- Use `uv` for Python project/dependency management.
|
|
19
|
+
- Do not manually author `pyproject.toml` or `uv.lock`; let `uv` generate/update them.
|
|
20
|
+
- Use this install set: `uv add weaviate-client python-dotenv dspy`
|
|
21
|
+
- Customise this cookbook to the users specification, ask them for details if not given.
|
|
22
|
+
|
|
23
|
+
Assume the user has data already to be used, do not create data unless asked to.
|
|
24
|
+
|
|
25
|
+
## Env Rules
|
|
26
|
+
|
|
27
|
+
Mandatory:
|
|
28
|
+
- `WEAVIATE_URL`
|
|
29
|
+
- `WEAVIATE_API_KEY`
|
|
30
|
+
|
|
31
|
+
External provider keys:
|
|
32
|
+
- Fill only keys actually used by the target Weaviate collection setup.
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
## Weaviate Client
|
|
36
|
+
|
|
37
|
+
```python
|
|
38
|
+
import os
|
|
39
|
+
from weaviate import connect_to_weaviate_cloud
|
|
40
|
+
|
|
41
|
+
client = connect_to_weaviate_cloud(
|
|
42
|
+
cluster_url=os.getenv("WEAVIATE_URL", ""),
|
|
43
|
+
auth_credentials=os.getenv("WEAVIATE_API_KEY", ""),
|
|
44
|
+
headers={
|
|
45
|
+
"X-OpenAI-Api-Key": os.getenv("OPENAI_API_KEY")
|
|
46
|
+
},
|
|
47
|
+
)
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
If the user's collections require vectorizer provider keys, set the matching keys listed in `environment_requirements.md`.
|
|
51
|
+
|
|
52
|
+
Clients must be closed after completion. Wrap in `try/finally` blocks with `client.close()` (and `client.connect()` to reconnect if needed).
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
## Multi-tenancy
|
|
56
|
+
|
|
57
|
+
Multi-tenancy should be checked via
|
|
58
|
+
|
|
59
|
+
```python
|
|
60
|
+
config = await collection.config.get()
|
|
61
|
+
config.multi_tenancy_config.enabled # bool
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
e.g.
|
|
65
|
+
|
|
66
|
+
```python
|
|
67
|
+
|
|
68
|
+
base_collection = client.collections.use(collection_name)
|
|
69
|
+
|
|
70
|
+
config = collection.config.get()
|
|
71
|
+
if config.multi_tenancy_config.enabled:
|
|
72
|
+
collection = base_collection.with_tenant("<tenant_name>")
|
|
73
|
+
else:
|
|
74
|
+
collection = base_collection
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
Tenant names can be obtained via
|
|
78
|
+
```python
|
|
79
|
+
all_tenants = list(collection.tenants.get().keys())
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## Basic Retrieval
|
|
83
|
+
|
|
84
|
+
Use collections via
|
|
85
|
+
|
|
86
|
+
```python
|
|
87
|
+
collection = client.collections.use("<collection_name>")
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
Weaviate can use vector, keyword or hybrid search.
|
|
91
|
+
|
|
92
|
+
```python
|
|
93
|
+
collection.query.near_text # semantic (text)
|
|
94
|
+
collection.query.bm25 # keyword
|
|
95
|
+
collection.query.hybrid # blend of keyword and semantic
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
It can also do image search
|
|
99
|
+
|
|
100
|
+
```python
|
|
101
|
+
collection.query.near_image(
|
|
102
|
+
near_image = ... # base 64 representation of image or Path object to image
|
|
103
|
+
)
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
## Key Code Blocks
|
|
107
|
+
|
|
108
|
+
RAG should have 4 pieces of core functionality:
|
|
109
|
+
|
|
110
|
+
1. Pre-retrieval
|
|
111
|
+
2. Retrieval
|
|
112
|
+
3. Post-retrieval
|
|
113
|
+
4. Generation
|
|
114
|
+
|
|
115
|
+
These should all be separate functions and combined into a single function, leaving scope for later editing or for the user themselves to modify it, to keep it understandable.
|
|
116
|
+
|
|
117
|
+
## Pre-retrieval
|
|
118
|
+
|
|
119
|
+
Transform the user question into a vector-database style (list of) query(ies). Basic RAG will provide no extra query transformations.
|
|
120
|
+
|
|
121
|
+
```python
|
|
122
|
+
def query_transformation(query: str) -> list[str]:
|
|
123
|
+
return [query]
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
## Retrieval
|
|
127
|
+
|
|
128
|
+
```python
|
|
129
|
+
def retrieve(
|
|
130
|
+
query: str,
|
|
131
|
+
limit: int = 10, # optional
|
|
132
|
+
filters = [] # optional
|
|
133
|
+
# additional arguments if required can go here and passed down to the search strategy
|
|
134
|
+
) -> list[dict]:
|
|
135
|
+
|
|
136
|
+
# import client logic here
|
|
137
|
+
|
|
138
|
+
collection = client.collections.use("<collection_name>")
|
|
139
|
+
|
|
140
|
+
response = collection.query.near_text( # or hybrid, bm25, near_image
|
|
141
|
+
query=query,
|
|
142
|
+
limit=limit,
|
|
143
|
+
filters=filters if filters else None
|
|
144
|
+
)
|
|
145
|
+
|
|
146
|
+
return [
|
|
147
|
+
{
|
|
148
|
+
**obj.properties,
|
|
149
|
+
"uuid": obj.uuid
|
|
150
|
+
}
|
|
151
|
+
for obj in response.objects
|
|
152
|
+
]
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
## Post-Retrieval
|
|
156
|
+
|
|
157
|
+
Modify the output of `retrieve`. Basic RAG will provide no extra post-processing. But you can consider adding uniqueness checks, formatting to remove properties, or more.
|
|
158
|
+
|
|
159
|
+
```python
|
|
160
|
+
def process_retrieval_results(objects: list[dict]) -> list[dict]:
|
|
161
|
+
return objects
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
## Generation
|
|
166
|
+
|
|
167
|
+
This step depends on your LLM framework, [see below](#user-specific-customisations). Using DSPy:
|
|
168
|
+
|
|
169
|
+
```python
|
|
170
|
+
import dspy
|
|
171
|
+
def generate(query: str, context: list[dict]) -> str:
|
|
172
|
+
lm = dspy.LM("<model_name>") # e.g. gpt-5.2, gpt-5-mini, claude-sonnet-4-5, etc.
|
|
173
|
+
answer = dspy.Predict("context, query -> answer") # inputs: context, query. outputs: answer
|
|
174
|
+
pred = answer(context=context, query=query, lm=lm)
|
|
175
|
+
return pred.answer # answer is then an attribute of pred
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
## User-specific Customisations
|
|
179
|
+
|
|
180
|
+
If not specified ask the user about these points before implementing their respective strategies:
|
|
181
|
+
|
|
182
|
+
**LLM Framework**
|
|
183
|
+
|
|
184
|
+
You can use DSPy (works with all LiteLLM providers) or LiteLLM itself.
|
|
185
|
+
|
|
186
|
+
- DSPy: https://dspy.ai/learn/programming/language_models/
|
|
187
|
+
- LiteLLM: https://docs.litellm.ai/docs/
|
|
188
|
+
|
|
189
|
+
Alternatively, users can use a single model provider. What model provider will they use?
|
|
190
|
+
|
|
191
|
+
- OpenAI (https://platform.openai.com/docs/libraries)
|
|
192
|
+
- Anthropic (https://platform.claude.com/docs/)
|
|
193
|
+
- Google GenAI (https://ai.google.dev/gemini-api/docs/libraries)
|
|
194
|
+
- Other (such as locally hosted models), use best judgement
|
|
195
|
+
|
|
196
|
+
These may require additional installs.
|
|
197
|
+
|
|
198
|
+
**Collections**
|
|
199
|
+
|
|
200
|
+
Do collections already exist and what are they called? Does the user want to query multiple collections or just a single one? Does it need to be customisable?
|
|
201
|
+
|
|
202
|
+
What format is the data, images or text or something else? What vectoriser is the collection set up as? What API keys are needed?
|
|
203
|
+
|
|
204
|
+
**Search strategy**
|
|
205
|
+
|
|
206
|
+
Does the user want semantic, keyword or hybrid search?
|
|
207
|
+
|
|
208
|
+
Hybrid search has an `alpha` parameter, controlling tradeoff between keyword and semantic weights. `alpha=1` is pure semantic, `alpha=0` is pure keyword.
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
## Troubleshooting
|
|
212
|
+
|
|
213
|
+
- Weaviate startup host errors: ensure `WEAVIATE_URL` is full `https://...` URL.
|
|
214
|
+
- For any other issues, refer to the official library/package documentation and use web search extensively for troubleshooting.
|
|
215
|
+
|
|
216
|
+
## Done Criteria
|
|
217
|
+
|
|
218
|
+
- Create test scripts to check each function works independently with test data. Tear down tests after completion, or create a proper test suite with pytest (requires install)
|
|
219
|
+
- User has completed specification of the app.
|
|
@@ -0,0 +1,336 @@
|
|
|
1
|
+
# Build Data Explorer App
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
Build a full-stack Data Explorer App for Weaviate Collections with FastAPI.
|
|
6
|
+
|
|
7
|
+
Read first:
|
|
8
|
+
- Search patterns and basics in Weaviate: https://docs.weaviate.io/weaviate/search/basics
|
|
9
|
+
- Filters in Weaviate: https://docs.weaviate.io/weaviate/search/filters
|
|
10
|
+
|
|
11
|
+
## Instructions
|
|
12
|
+
|
|
13
|
+
### Core Rules
|
|
14
|
+
|
|
15
|
+
- Use a virtual environment via `venv`
|
|
16
|
+
- Use `uv` for Python project/dependency management.
|
|
17
|
+
- Do not manually author `pyproject.toml` or `uv.lock`; let `uv` generate/update them.
|
|
18
|
+
- Use this backend install set:
|
|
19
|
+
- `uv add fastapi 'uvicorn[standard]' weaviate-client pydantic-settings python-dotenv`
|
|
20
|
+
- Depending on user request: consider combining this app with the [Query Agent Chatbot](./query_agent_chatbot.md).
|
|
21
|
+
- If the user explicitly only wants a data viewer/explorer, create this app independently
|
|
22
|
+
- If the user wants a fully featured chat and data explorer, combine the apps
|
|
23
|
+
- If no explicit instructions are given, ask the user their preference before continuing
|
|
24
|
+
- See the [Next Steps](#next-steps) section for more details
|
|
25
|
+
|
|
26
|
+
### Fast Setup Commands
|
|
27
|
+
|
|
28
|
+
Project bootstrap:
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
uv init data_explorer
|
|
32
|
+
cd data_explorer
|
|
33
|
+
uv venv
|
|
34
|
+
uv add fastapi 'uvicorn[standard]' weaviate-client pydantic-settings python-dotenv
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### Workflow Contract
|
|
38
|
+
|
|
39
|
+
1. Build backend and frontend in one pass.
|
|
40
|
+
2. Create `.env` from the canonical template in `environment_requirements.md`, then add app-specific fields (for example, `CORS_ORIGINS`).
|
|
41
|
+
3. Before asking user to fill env, do non-secret local sanity checks that do not require real credentials (imports/compile/startup-shape checks).
|
|
42
|
+
4. Ask user to fill real env values:
|
|
43
|
+
- Mandatory: `WEAVIATE_URL`, `WEAVIATE_API_KEY`
|
|
44
|
+
- Optional: only provider keys required by their collection setup
|
|
45
|
+
5. After the user confirms, verify backend starts without errors and provide exact commands to run in the terminal.
|
|
46
|
+
|
|
47
|
+
Do not ask avoidable questions that you can resolve from context.
|
|
48
|
+
|
|
49
|
+
### Directory Structure
|
|
50
|
+
|
|
51
|
+
Use a modular layout like:
|
|
52
|
+
|
|
53
|
+
```text
|
|
54
|
+
data_explorer/
|
|
55
|
+
backend/
|
|
56
|
+
app/
|
|
57
|
+
main.py
|
|
58
|
+
config.py
|
|
59
|
+
lifespan.py
|
|
60
|
+
dependencies.py
|
|
61
|
+
routers/
|
|
62
|
+
services/
|
|
63
|
+
models/
|
|
64
|
+
.env # local file, never committed
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Keep these boundaries:
|
|
68
|
+
|
|
69
|
+
- routers: HTTP only
|
|
70
|
+
- services: business/query-agent logic
|
|
71
|
+
- models: request/response schemas
|
|
72
|
+
- config/lifespan: wiring and startup/shutdown
|
|
73
|
+
|
|
74
|
+
### Backend Requirements
|
|
75
|
+
|
|
76
|
+
- FastAPI async app with lifespan.
|
|
77
|
+
- Async Weaviate client initialized in lifespan and closed on shutdown.
|
|
78
|
+
- Ensure no async blocking operations.
|
|
79
|
+
- Not a full CRUD implementation - this is only for viewing data in a Weaviate collection.
|
|
80
|
+
- Endpoints for:
|
|
81
|
+
- `GET /health`
|
|
82
|
+
- `GET /env_check`: returns what API keys are missing (if any) for verification on app start
|
|
83
|
+
- `GET /collections`: return available collections
|
|
84
|
+
- `GET /data/{collection_name}?xx=xx&yy=yy`: return data with optional arguments (more later), and pagination
|
|
85
|
+
- Pydantic settings should read from process environment; local `.env` loading is optional for local development.
|
|
86
|
+
- Conversation history mapping to Weaviate chat message format.
|
|
87
|
+
|
|
88
|
+
### Env Rules
|
|
89
|
+
|
|
90
|
+
Mandatory:
|
|
91
|
+
- `WEAVIATE_URL`
|
|
92
|
+
- `WEAVIATE_API_KEY`
|
|
93
|
+
|
|
94
|
+
External provider keys:
|
|
95
|
+
- Include every provider key needed by the target collections.
|
|
96
|
+
- Leave unused provider keys empty/commented.
|
|
97
|
+
|
|
98
|
+
CORS:
|
|
99
|
+
|
|
100
|
+
- Default `CORS_ORIGINS` should include:
|
|
101
|
+
- `http://localhost:3000`
|
|
102
|
+
- `http://127.0.0.1:3000`
|
|
103
|
+
- `http://localhost:5173`
|
|
104
|
+
- `http://127.0.0.1:5173`
|
|
105
|
+
|
|
106
|
+
### FastAPI standards
|
|
107
|
+
|
|
108
|
+
1. Do not use hardcoded status values, use `status` from FastAPI, for example:
|
|
109
|
+
|
|
110
|
+
```python
|
|
111
|
+
from fastapi import status
|
|
112
|
+
status.HTTP_200_OK # code 200
|
|
113
|
+
status.HTTP_404_NOT_FOUND # code 404
|
|
114
|
+
# and more
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
2. Use a Pydantic `BaseModel` for the `request` and `response_model` in all endpoints that require it. Ensure schema validation to mitigate user-error on the API.
|
|
118
|
+
|
|
119
|
+
3. Use path parameters and query parameters for GET endpoints instead of payloads, for example:
|
|
120
|
+
|
|
121
|
+
```python
|
|
122
|
+
@app.get("/items/{item_id}")
|
|
123
|
+
async def read_item(item_id: str):
|
|
124
|
+
return {"item_id": item_id}
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
```python
|
|
128
|
+
@app.get("/items/")
|
|
129
|
+
async def read_item(skip: int = 0, limit: int = 10):
|
|
130
|
+
return fake_items_db[skip : skip + limit]
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
4. Implement best practices for error-handling, do early returns and provide the correct status codes when necessary.
|
|
134
|
+
|
|
135
|
+
5. Use proper logging for API usage, not simple print statements.
|
|
136
|
+
|
|
137
|
+
### FastAPI endpoints
|
|
138
|
+
|
|
139
|
+
Basic structure of endpoints. Customise according to user preference or suitability. Do not follow exactly, this is a guideline only.
|
|
140
|
+
|
|
141
|
+
Ensure you also set up standard FastAPI procedures, such as global error handling, logging, dependencies. Set up an async client manager that connects on startup (via lifespan) and closes gracefully on app exit, use a dependency injection to add the client to the relevant endpoints.
|
|
142
|
+
|
|
143
|
+
#### GET /health
|
|
144
|
+
|
|
145
|
+
This is a standard health check. For example:
|
|
146
|
+
|
|
147
|
+
```python
|
|
148
|
+
from pydantic import BaseModel
|
|
149
|
+
|
|
150
|
+
class HealthResponse(BaseModel):
|
|
151
|
+
status: str
|
|
152
|
+
|
|
153
|
+
@app.get("/health", tags=["health"], response_model=HealthResponse)
|
|
154
|
+
async def health_check() -> HealthResponse:
|
|
155
|
+
logger.info("Health check requested")
|
|
156
|
+
return HealthResponse(status="healthy")
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
#### GET /env_check
|
|
160
|
+
|
|
161
|
+
Check what environment variables the backend has access to, used to verify the user's Weaviate configuration is correct. For example:
|
|
162
|
+
|
|
163
|
+
```python
|
|
164
|
+
import os
|
|
165
|
+
from pydantic import BaseModel
|
|
166
|
+
|
|
167
|
+
class EnvCheckResponse(BaseModel):
|
|
168
|
+
weaviate_url: bool
|
|
169
|
+
weaviate_api_key: bool
|
|
170
|
+
|
|
171
|
+
@app.get("/env_check", tags=["health"])
|
|
172
|
+
async def env_check() -> EnvCheckResponse:
|
|
173
|
+
logger.info("Environment check requested")
|
|
174
|
+
return EnvCheckResponse(
|
|
175
|
+
weaviate_url = os.getenv("WEAVIATE_URL") is not None,
|
|
176
|
+
weaviate_api_key = os.getenv("WEAVIATE_API_KEY") is not None,
|
|
177
|
+
)
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
### GET /collections
|
|
181
|
+
|
|
182
|
+
Check what collections are available. For example:
|
|
183
|
+
|
|
184
|
+
```python
|
|
185
|
+
from pydantic import BaseModel
|
|
186
|
+
from weaviate.client import WeaviateAsyncClient
|
|
187
|
+
|
|
188
|
+
class CollectionsResponse(BaseModel):
|
|
189
|
+
collections: list[str]
|
|
190
|
+
|
|
191
|
+
@app.get("/collections", tags=["collections"])
|
|
192
|
+
async def collections() -> CollectionsResponse:
|
|
193
|
+
|
|
194
|
+
# include client management to import async client here
|
|
195
|
+
|
|
196
|
+
logger.info("Collections requested")
|
|
197
|
+
collections = await client.collections.list_all()
|
|
198
|
+
return CollectionsResponse(
|
|
199
|
+
collections = list(collections.keys())
|
|
200
|
+
)
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
Tip: consider expanding this endpoint to include collection descriptions and configs. `await client.collections.list_all()` returns `dict[str, _CollectionConfigSimple]` where `_CollectionConfigSimple` contains attributes:
|
|
204
|
+
|
|
205
|
+
- `description`: `str`
|
|
206
|
+
- `properties`: `list[Property]` where `Property` has `.name`, `.description` and `.data_type` (accessed via `.data_type[:]` to get name of data type as string)
|
|
207
|
+
- `vector_config`: `dict[str, _NamedVectorConfig]` where `_NamedVectorConfig` has attribute `.vectorizer.vectorizer` (not a typo) which can be accessed via `.vectorizer.vectorizer[:]` to get the name of the vectoriser as a string.
|
|
208
|
+
|
|
209
|
+
Multi-tenancy should be checked via
|
|
210
|
+
|
|
211
|
+
```python
|
|
212
|
+
config = await collection.config.get()
|
|
213
|
+
config.multi_tenancy_config.enabled # bool
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
This is not available in the `_CollectionConfigSimple`, it must be fetched from `collection.config.get()`.
|
|
217
|
+
|
|
218
|
+
#### GET /data/{collection_name}
|
|
219
|
+
|
|
220
|
+
Retrieve data from a collection, using pagination, sorting and filters.
|
|
221
|
+
|
|
222
|
+
```python
|
|
223
|
+
from weaviate.collections import CollectionAsync
|
|
224
|
+
from fastapi import Query
|
|
225
|
+
from pydantic import BaseModel
|
|
226
|
+
from typing import Any
|
|
227
|
+
|
|
228
|
+
async def get_collection_data_types(collection: CollectionAsync) -> dict[str, str]:
|
|
229
|
+
config = await collection.config.get()
|
|
230
|
+
properties = config.properties
|
|
231
|
+
return {prop.name: prop.data_type[:] for prop in properties}
|
|
232
|
+
|
|
233
|
+
class GetDataResponse(BaseModel):
|
|
234
|
+
data_types: dict[str, str]
|
|
235
|
+
items: list[dict[str, Any]]
|
|
236
|
+
|
|
237
|
+
@router.post("/data/{collection_name}")
|
|
238
|
+
async def get_data(
|
|
239
|
+
collection_name: str,
|
|
240
|
+
page_size: int = Query(default=10, ge=1, le=100),
|
|
241
|
+
page_number: int = Query(default=1, ge=1),
|
|
242
|
+
query: str = Query(default=""),
|
|
243
|
+
sort_on: str = Query(default=None),
|
|
244
|
+
ascending: bool = Query(default=True),
|
|
245
|
+
) -> GetDataResponse:
|
|
246
|
+
|
|
247
|
+
# include client management to import async client here
|
|
248
|
+
|
|
249
|
+
collection = await client.collections.use(collection_name)
|
|
250
|
+
data_types = await async_get_collection_data_types(collection)
|
|
251
|
+
|
|
252
|
+
if query != "":
|
|
253
|
+
response = await collection.query.bm25(
|
|
254
|
+
query=query,
|
|
255
|
+
limit=page_size,
|
|
256
|
+
offset=page_size * (page_number - 1),
|
|
257
|
+
)
|
|
258
|
+
elif sort_on is not None:
|
|
259
|
+
response = await collection.query.fetch_objects(
|
|
260
|
+
sort=Sort.by_property(name=sort_on, ascending=ascending),
|
|
261
|
+
limit=page_size,
|
|
262
|
+
offset=page_size * (page_number - 1),
|
|
263
|
+
)
|
|
264
|
+
else:
|
|
265
|
+
response = await collection.query.fetch_objects(
|
|
266
|
+
limit=page_size,
|
|
267
|
+
offset=page_size * (page_number - 1),
|
|
268
|
+
)
|
|
269
|
+
|
|
270
|
+
return GetDataResponse(data_types = data_types, items = [obj.properties for obj in response.objects])
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
Tip: some collections can have multi-tenancy.
|
|
274
|
+
Consider adding the tenant as an optional query parameter to `get_data`, e.g.
|
|
275
|
+
|
|
276
|
+
```python
|
|
277
|
+
async def get_data(
|
|
278
|
+
... # existing args
|
|
279
|
+
tenant: str | None = Query(default=None)
|
|
280
|
+
):
|
|
281
|
+
base_collection = await client.collections.use(collection_name)
|
|
282
|
+
data_types = await async_get_collection_data_types(collection)
|
|
283
|
+
|
|
284
|
+
config = await collection.config.get()
|
|
285
|
+
if config.multi_tenancy_config.enabled and tenant and tenant.strip():
|
|
286
|
+
collection = base_collection.with_tenant(tenant)
|
|
287
|
+
else:
|
|
288
|
+
collection = base_collection
|
|
289
|
+
|
|
290
|
+
# ...existing code
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
### Post-Env Hand-Holding (Required)
|
|
294
|
+
|
|
295
|
+
After user says required env values are set, provide the terminal commands to run the backend:
|
|
296
|
+
|
|
297
|
+
```bash
|
|
298
|
+
cd data_explorer/backend
|
|
299
|
+
uv run uvicorn app.main:app --reload --host 127.0.0.1 --port 8000
|
|
300
|
+
```
|
|
301
|
+
|
|
302
|
+
Then:
|
|
303
|
+
|
|
304
|
+
- Ask user to start terminal.
|
|
305
|
+
- Run smoke tests yourself against running services.
|
|
306
|
+
- Report pass/fail in plain language and fix blockers.
|
|
307
|
+
|
|
308
|
+
Do not offload detailed testing steps to the user unless they explicitly ask.
|
|
309
|
+
|
|
310
|
+
## Troubleshooting
|
|
311
|
+
|
|
312
|
+
- Weaviate startup host errors: ensure `WEAVIATE_URL` is full `https://...` URL.
|
|
313
|
+
- For any other issues, refer to the official library/package documentation using web search.
|
|
314
|
+
|
|
315
|
+
## Done Criteria
|
|
316
|
+
|
|
317
|
+
- Backend healthy.
|
|
318
|
+
- All endpoints work.
|
|
319
|
+
- User can run server in terminal with provided commands.
|
|
320
|
+
|
|
321
|
+
## Next Steps
|
|
322
|
+
|
|
323
|
+
This application is currently a data explorer backend. You may optionally offer to integrate it with the [Query Agent Chatbot](./query_agent_chatbot.md) based on user preference.
|
|
324
|
+
|
|
325
|
+
If the user chooses to combine these two applications, implement the integration as follows:
|
|
326
|
+
|
|
327
|
+
- Create or use a directory `/routes` which separate functions for query agent chat and data exploration. Import the routers in the `main.py` file
|
|
328
|
+
- If a frontend is requested, the frontend should have multiple pages/tabs depending on design choices so that data exploration and chat is separated
|
|
329
|
+
- Consider crossovers between functionalities, e.g. a chat button from the data viewer/collection viewer which takes the user to chat with that collection selected.
|
|
330
|
+
- Run quick tests to ensure the integration is seamless and the user can use both the chatbot and data explorer without any issues.
|
|
331
|
+
|
|
332
|
+
### Frontend
|
|
333
|
+
|
|
334
|
+
When the user explicitly asks for a frontend, use this reference as guideline:
|
|
335
|
+
|
|
336
|
+
- [Frontend Interface](frontend_interface.md): Build a Next.js frontend to interact with the Weaviate backend.
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
# Environment Requirements for Weaviate
|
|
2
|
+
|
|
3
|
+
Use this reference when building apps that connect to Weaviate and require external inference provider keys.
|
|
4
|
+
|
|
5
|
+
## Required Weaviate Auth
|
|
6
|
+
|
|
7
|
+
- `WEAVIATE_URL`
|
|
8
|
+
- `WEAVIATE_API_KEY`
|
|
9
|
+
|
|
10
|
+
## External Provider Env Vars and Headers
|
|
11
|
+
|
|
12
|
+
| Provider | Environment Variable(s) | Header(s) sent to Weaviate |
|
|
13
|
+
|----------|--------------------------|-----------------------------|
|
|
14
|
+
| Anthropic | `ANTHROPIC_API_KEY` | `X-Anthropic-Api-Key` |
|
|
15
|
+
| Anyscale | `ANYSCALE_API_KEY` | `X-Anyscale-Api-Key` |
|
|
16
|
+
| AWS | `AWS_ACCESS_KEY`, `AWS_SECRET_KEY` | `X-Aws-Access-Key`, `X-Aws-Secret-Key` |
|
|
17
|
+
| Cohere | `COHERE_API_KEY` | `X-Cohere-Api-Key` |
|
|
18
|
+
| Databricks | `DATABRICKS_TOKEN` | `X-Databricks-Token` |
|
|
19
|
+
| Friendli | `FRIENDLI_TOKEN` | `X-Friendli-Api-Key` |
|
|
20
|
+
| Google Vertex AI | `VERTEX_API_KEY` | `X-Goog-Vertex-Api-Key` |
|
|
21
|
+
| Google AI Studio | `STUDIO_API_KEY` | `X-Goog-Studio-Api-Key` |
|
|
22
|
+
| HuggingFace | `HUGGINGFACE_API_KEY` | `X-HuggingFace-Api-Key` |
|
|
23
|
+
| Jina AI | `JINAAI_API_KEY` | `X-JinaAI-Api-Key` |
|
|
24
|
+
| Mistral | `MISTRAL_API_KEY` | `X-Mistral-Api-Key` |
|
|
25
|
+
| NVIDIA | `NVIDIA_API_KEY` | `X-Nvidia-Api-Key` |
|
|
26
|
+
| OpenAI | `OPENAI_API_KEY` | `X-OpenAI-Api-Key` |
|
|
27
|
+
| Azure OpenAI | `AZURE_API_KEY` | `X-Azure-Api-Key` |
|
|
28
|
+
| Voyage AI | `VOYAGE_API_KEY` | `X-Voyage-Api-Key` |
|
|
29
|
+
| xAI | `XAI_API_KEY` | `X-Xai-Api-Key` |
|
|
30
|
+
|
|
31
|
+
## Usage Notes
|
|
32
|
+
|
|
33
|
+
- Set only the provider keys your collection configuration actually uses.
|
|
34
|
+
- If multiple providers are configured, include all corresponding headers.
|
|
35
|
+
|
|
36
|
+
## Canonical `.env` Template
|
|
37
|
+
|
|
38
|
+
Use this template in all cookbook apps. Then ask the user to fill only the values their app actually needs.
|
|
39
|
+
|
|
40
|
+
`WEAVIATE_URL` and `WEAVIATE_API_KEY` are mandatory for Weaviate-connected apps.
|
|
41
|
+
|
|
42
|
+
```dotenv
|
|
43
|
+
# Required for Weaviate cookbook apps (must be filled by user)
|
|
44
|
+
WEAVIATE_URL=
|
|
45
|
+
WEAVIATE_API_KEY=
|
|
46
|
+
|
|
47
|
+
# Common app-level settings (uncomment when needed by the selected cookbook)
|
|
48
|
+
# COLLECTIONS=
|
|
49
|
+
# CORS_ORIGINS=http://localhost:3000,http://127.0.0.1:3000,http://localhost:5173,http://127.0.0.1:5173
|
|
50
|
+
|
|
51
|
+
# External provider keys (uncomment only what the target collection uses)
|
|
52
|
+
# ANTHROPIC_API_KEY=
|
|
53
|
+
# ANYSCALE_API_KEY=
|
|
54
|
+
# AWS_ACCESS_KEY=
|
|
55
|
+
# AWS_SECRET_KEY=
|
|
56
|
+
# AZURE_API_KEY=
|
|
57
|
+
# COHERE_API_KEY=
|
|
58
|
+
# DATABRICKS_TOKEN=
|
|
59
|
+
# FRIENDLI_TOKEN=
|
|
60
|
+
# HUGGINGFACE_API_KEY=
|
|
61
|
+
# JINAAI_API_KEY=
|
|
62
|
+
# MISTRAL_API_KEY=
|
|
63
|
+
# NVIDIA_API_KEY=
|
|
64
|
+
# OPENAI_API_KEY=
|
|
65
|
+
# STUDIO_API_KEY=
|
|
66
|
+
# VERTEX_API_KEY=
|
|
67
|
+
# VOYAGE_API_KEY=
|
|
68
|
+
# XAI_API_KEY=
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## User Fill Guidance (Required)
|
|
72
|
+
|
|
73
|
+
1. Create a local `.env` file from this template.
|
|
74
|
+
2. Always ask the user to fill:
|
|
75
|
+
- `WEAVIATE_URL`
|
|
76
|
+
- `WEAVIATE_API_KEY`
|
|
77
|
+
3. Ask them to uncomment and fill only the provider keys their Weaviate collections require.
|
|
78
|
+
4. Keep `.env` local only and gitignored.
|