AI

BookRecs: Next.js + Weaviate Starter

BookRecs: Next.js + Weaviate Starter
Type: Code
Framework: Next.js
CSS: Tailwind

Book Recommendation System (BookRecs)

This project is a book recommendation service that suggests books based on a user’s inputted genre and book titles. It’s built upon a database of 7000 books retrieved from Kaggle. Using Ada v2 as the large language model, vector embeddings were created with the Kaggle dataset to allow for quick vector search to find semantically similar books through natural language input. The frontend is built using Next.js and styled with TailwindCSS.

šŸ“‘ Table of Contents

  • Features
  • Installation
  • Usage
  • Data Source
  • Tech Stack
  • Contributing
  • License

šŸ’« Features

  • Input genre and book titles to get book recommendations
  • Vector Search on Weaviate Vector database of 7000 books
  • Jupyter Notebook workflow to access and store vector embeddings in Weaviate
  • Responsive design, thanks to TailwindCSS

šŸ›  Installation

To run the project locally, follow these steps:

  1. Clone the repository

    git clone https://github.com/weaviate/BookRecs.git
    
  2. Optionally, create a Weaviate Cluster using theĀ Weaviate ConsoleĀ and make note of the cluster URL and the API Key. The project is already configured to read from an existing Weaviate Cluster. If you choose not to create a new Weaviate Cluster, you can rely on the default cluster we’ve already created for you. It’s configured in both the NextJS app and the Python data pipeline.

  3. Create a OpenAI account and create API Key.

  4. Set up environment variables in .env

    cp env.example .env
    

    OPENAI_API_KEYĀ is required. If you don’t choose not to create the Weaviate Cluster, removeĀ WEAVIATE_CLUSTER_URLĀ andĀ WEAVIATE_API_KEYĀ from theĀ .env.

  5. Set up a Python virtualenv to populate your vector database and to experiment with semantic search.

    python3 -m venv venv 
    source venv/bin/activate
    pip install -r requirements.txt
    python data-pipeline/populate.py # Will only work if you create your own cluster
    python data-pipeline/search.py
    
  6. Install dependencies

    cd bookrecs
    npm install
    
  7. Run the app

    npm run dev
    
  8. Try out BookRecs in a browser at http://localhost:3000

šŸ¤ Configuring Cohere Integration

This project provides book recommendations using a vector database for semantic search. An additional feature is the integration with Cohere through the Weaviate Generative Search module, which provides explainations as to why a user might like a particular book recommendation.

If you would like to enable this feature, you will need to configure the COHERE_API_KEY and NEXT_PUBLIC_COHERE_CONFIGURED environment variables.

Steps

  1. Obtain a Cohere API key by signing up on theĀ Cohere website.
  2. Once you have your API key, open the .env file in the root directory of the project.
  3. Add the following line to the file, replacing ‘INSERT_OPEN_API_KEY_HERE’ with the API key you obtained from Cohere:
COHERE_API_KEY=INSERT_OPENAPI_KEY_HERE
  1. To enable the Cohere integration, set the NEXT_PUBLIC_COHERE_CONFIGURED environment variable to “1”. Add the following line to the .env file:
NEXT_PUBLIC_COHERE_CONFIGURED=1
  1. Save the .env file and restart your development server. The Cohere integration should now be enabled.

Please note that the COHERE_API_KEY should be kept secret and not exposed to the client-side of your application.

šŸ§° Usage

To use the service, simply type in a genre and several book titles in the provided input fields. The system will then generate several book recommendations based on your inputs.

You can try this atĀ https://bookrecs.weaviate.io

You must set at least on OPENAI_API_KEY environment variable. You can also set up your own Weaviate cluster and create embeddings yourself. If you choose not to do this, BookRecs will use a Read Only API key for an existing Weaviate cluster containing the Kaggle dataset.

šŸ’¾ Data Source

The book data used for this project is sourced from the following Kaggle dataset:Ā 7k books with metadata. The dataset has been converted to a vector embedding using the sentence-transformer model for improved natural language processing and stored in a Weaviate clustor for fast vector lookups.

šŸ’» Tech Stack

šŸ•· Known Issues

  • Some book images are inaccessible due to dead links on the original data set

šŸ’° Large Language Model (LLM) Costs

BookRecs exclusively utilizes OpenAI models. Be advised that the usage costs for these models will be billed to the API access key you provide. Primarily, costs are incurred during data embedding and answer generation processes. The default vectorization engine for this project isĀ Ada v2.

šŸ’– Open Source Contribution

Your contributions are always welcome! Feel free to contribute ideas, feedback, or create issues and bug reports if you find any! Visit ourĀ Weaviate Community ForumĀ if you need any help!

Sign In

Register

Reset Password

Please enter your username or email address, you will receive a link to create a new password via email.