Skip to content

weaviate-tutorials/BookStore

Repository files navigation

WeaviateBookstore

An ASP.NET Core application that integrates with Weaviate vector database, featuring a wizard-style UI for managing book collections.

Features

  • Step 1: Connection & Configuration - Connect to Weaviate with custom URL, API key, and headers (including OpenAI API key for generative search)
  • Step 2: Schema Creation - Create the Book collection in Weaviate
  • Step 3: Data Import - Import up to 100 books from the provided CSV file
  • Step 4: Search - Search books using:
    • Similarity (Vector search)
    • Keyword (BM25)
    • Hybrid (Combined vector + keyword)
    • Generative (RAG with OpenAI)

Prerequisites

  • .NET 8.0 SDK
  • A Weaviate instance (cloud or local)
  • (Optional) OpenAI API key for generative search

Getting Started

  1. Restore dependencies:

    dotnet restore
  2. Run the application:

    dotnet run
  3. Open your browser: Navigate to https://localhost:5001 or http://localhost:5000

Usage

Step 1: Connection

  1. Enter your Weaviate URL:
    • Cloud: my-cluster.weaviate.cloud or https://my-cluster.weaviate.cloud
    • Local: localhost:8080 or http://localhost:8080
    • Scheme (http:// or https://) is optional - defaults to https:// if not provided
  2. Enter your Weaviate API key (optional for localhost without authentication)
  3. (Optional) Add additional headers:
    • Key: X-OpenAI-Api-Key
    • Value: Your OpenAI API key (required for Generative search)
  4. Click "Connect & Test"

Step 2: Create Collection

Click "Create Book Collection" to create the schema in Weaviate.

Step 3: Import Data

Click "Import Data" to load the first 100 books from books.csv.

Step 4: Search

  1. Enter your search query
  2. Select a search mode:
    • Similarity: Vector-based semantic search
    • Keyword: BM25 keyword search
    • Hybrid: Combined vector and keyword search
    • Generative: RAG-based search with AI-generated summaries (requires OpenAI API key)
  3. Click "Search" to view results

Project Structure

WeaviateBookstore/
├── Controllers/
│   └── WeaviateController.cs      # API endpoints
├── Models/
│   └── Book.cs                     # Data models
├── Pages/
│   ├── Index.cshtml                # Main wizard UI
│   ├── Index.cshtml.cs             # Page model
│   └── _ViewImports.cshtml         # View imports
├── Services/
│   └── WeaviateService.cs          # Weaviate integration logic
├── wwwroot/
│   └── css/
│       └── site.css                # Styling
├── books.csv                       # Sample book data
├── Program.cs                      # Application entry point
└── WeaviateBookstore.csproj        # Project file

Key Implementation Details

Dynamic Client Configuration

The application does NOT use appsettings.json for Weaviate configuration. Instead, it:

  • Accepts connection details from the UI
  • Creates a WeaviateClient instance dynamically
  • Stores the client in memory keyed by session ID

CSV Import Limit

The import is strictly limited to 100 rows as specified in the requirements.

Vectorization

The Book collection uses the following vectorized fields:

  • Title
  • Authors
  • Publisher

Search Modes

Each search mode uses the appropriate Weaviate C# client method:

  • Similarity: Query.NearText()
  • Keyword: Query.BM25()
  • Hybrid: Query.Hybrid()
  • Generative: Generate.NearText() with single prompt

Technologies Used

  • ASP.NET Core 8.0 (Razor Pages)
  • Weaviate C# Client
  • CsvHelper for CSV parsing
  • Vanilla JavaScript for UI interactions

Notes

  • The UI follows a dark-themed accordion/wizard design
  • Steps are enabled sequentially after successful completion of previous steps
  • Session state is used to maintain the Weaviate client across requests
  • All Weaviate client syntax follows the examples from the /syntax directory

About

An ASP.NET Core application that integrates with Weaviate for managing book collections.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published