This sample demonstrates how to use Weaviate as a vector database for RAG (Retrieval Augmented Generation) workflows with Genkit.
- Weaviate Instance: Either local or cloud-hosted
- Google GenAI API Key: For embeddings and LLM
docker run -d \
--name weaviate \
-p 8080:8080 \
-p 50051:50051 \
-e QUERY_DEFAULTS_LIMIT=25 \
-e AUTHENTICATION_ANONYMOUS_ACCESS_ENABLED=true \
-e PERSISTENCE_DATA_PATH=/var/lib/weaviate \
-e DEFAULT_VECTORIZER_MODULE=none \
-e CLUSTER_HOSTNAME=node1 \
cr.weaviate.io/semitechnologies/weaviate:1.27.0| Variable | Required | Description |
|---|---|---|
GEMINI_API_KEY |
Yes | Google GenAI API key |
WEAVIATE_HOST |
No | Weaviate host (default: localhost) |
WEAVIATE_PORT |
No | Weaviate HTTP port (default: 8080) |
WEAVIATE_GRPC_PORT |
No | Weaviate gRPC port (default: 50051) |
WEAVIATE_API_KEY |
No | API key for Weaviate Cloud |
-
Copy the example environment file:
cp .env.example .env
-
Edit
.envand set your API key:GEMINI_API_KEY=your-api-key -
Run the sample:
./run.sh
# Set required environment variables
export GEMINI_API_KEY="your-api-key"
# Optional: For Weaviate Cloud
# export WEAVIATE_HOST="your-cluster.weaviate.network"
# export WEAVIATE_API_KEY="your-weaviate-api-key"
# Run the sample
./run.shOr with Maven directly:
mvn exec:java -Dexec.mainClass="com.google.genkit.samples.weaviate.WeaviateRAGSample"Indexes sample documents about famous films into Weaviate.
curl -X POST http://localhost:4000/api/flows/indexDocuments \
-H 'Content-Type: application/json' \
-d '{}'Retrieves documents matching a semantic query.
curl -X POST http://localhost:4000/api/flows/retrieveDocuments \
-H 'Content-Type: application/json' \
-d '{"data": "sci-fi movies"}'Answers questions using RAG with retrieved context.
curl -X POST http://localhost:4000/api/flows/ragQuery \
-H 'Content-Type: application/json' \
-d '{"data": "What Christopher Nolan films are mentioned?"}'- Start the sample application
- Index the sample documents:
curl -X POST http://localhost:4000/api/flows/indexDocuments -H 'Content-Type: application/json' -d '{}'
- Query for relevant documents:
curl -X POST http://localhost:4000/api/flows/retrieveDocuments -H 'Content-Type: application/json' -d '{"data": "movies about dreams"}'
- Ask questions using RAG:
curl -X POST http://localhost:4000/api/flows/ragQuery -H 'Content-Type: application/json' -d '{"data": "Which films were directed by Christopher Nolan and what are they about?"}'
The sample uses:
- Embedder:
googleai/text-embedding-004(768 dimensions) - LLM:
googleai/gemini-2.0-flash - Distance Metric: Cosine similarity
- Collection Name:
Films
You can modify these settings in WeaviateRAGSample.java.