This directory contains example implementations demonstrating how to use the genkitx-weaviate plugin with Genkit.
Before running these examples, make sure you have:
- Node.js >= 20.0.0 installed
- A Weaviate instance running (local or cloud)
- An OpenAI API key (for embeddings and LLM)
From the root of the repository:
npm install
npm run buildThen in this examples directory:
cd examples
npm installCreate a .env file in this directory with the following variables:
# OpenAI API Key (required for embeddings and LLM)
OPENAI_API_KEY=your_openai_api_key_here
# Weaviate Configuration (Local)
WEAVIATE_HOST=http://localhost:8080
# Optional: Weaviate Cloud Configuration
# WEAVIATE_HOST=https://your-cluster.weaviate.network
# WEAVIATE_API_KEY=your_weaviate_api_keyIf you don't have a Weaviate instance running, you can start one locally using Docker:
docker run -d \
-p 8080:8080 \
-p 50051:50051 \
--name weaviate \
-e AUTHENTICATION_ANONYMOUS_ACCESS_ENABLED=true \
-e PERSISTENCE_DATA_PATH=/var/lib/weaviate \
-e QUERY_DEFAULTS_LIMIT=25 \
-e DEFAULT_VECTORIZER_MODULE=none \
-e CLUSTER_HOSTNAME=node1 \
cr.weaviate.io/semitechnologies/weaviate:latestFor more information, see the Weaviate documentation.
npm run build
npm run genkit:startThis will:
- Compile the TypeScript code
- Start the Genkit development UI
- Watch for file changes and rebuild automatically
The Genkit Developer UI will open in your browser at http://localhost:4000
Name: retrieverFlow
Description: Demonstrates basic retrieval from Weaviate. Takes a query string and returns an AI-generated response based on retrieved documents.
Input: String (query)
Example:
"What is Weaviate?"Name: indexerFlow
Description: Indexes a local PDF file into Weaviate. Uses the sample PDF in the doc/ folder.
Input: String (ignored, can be empty)
Example:
""Name: indexerUrlFlow
Description: Indexes content from URLs into Weaviate. Demonstrates web scraping and indexing.
Input: String (ignored, can be empty)
Example:
""Name: retrieverWithFiltersFlow
Description: Advanced retrieval with Weaviate filters. Shows how to filter results by category and distance threshold.
Input: Object with query and optional category
Example:
{
"query": "What is vector search?",
"category": "documentation"
}examples/
├── doc/ # Sample documents for indexing
│ └── sample.pdf # Example PDF file
├── src/ # Source code
│ └── index.ts # Main example flows
├── lib/ # Compiled JavaScript (generated)
├── .env # Environment variables (create this)
├── .env.example # Environment variables template
├── .gitignore # Git ignore file
├── package.json # Node.js dependencies
├── tsconfig.json # TypeScript configuration
└── README.md # This file
The examples show two ways to index data into Weaviate:
- Local files: Using
file://URLs to index local documents - Web URLs: Using HTTP/HTTPS URLs to index web content
The examples demonstrate:
- Basic retrieval: Simple vector search with k-nearest neighbors
- Filtered retrieval: Using Weaviate filters to narrow down results
- Distance thresholds: Setting similarity thresholds for results
The examples show how to:
- Configure the Weaviate plugin with embedders
- Use retrievers in Genkit flows
- Use indexers in Genkit flows
- Combine retrieval with LLM generation (RAG pattern)
If you can't connect to Weaviate:
- Verify Weaviate is running:
docker ps - Check the connection settings in
.env - Ensure the port (default 8080) is not blocked
If you get embedding errors:
- Verify your OpenAI API key is correct
- Check you have sufficient API credits
- Ensure the embedding model exists (
text-embedding-3-small)
If you encounter build errors:
- Ensure you've built the main plugin:
npm run buildin the root directory - Delete
node_modulesandpackage-lock.json, then runnpm installagain - Make sure you're using Node.js >= 20.0.0
- genkitx-weaviate Documentation
- Genkit Documentation
- Weaviate Documentation
- Weaviate Client Documentation
This project is licensed under the Apache 2.0 License - see the LICENSE file for details.