Giter Site home page Giter Site logo

itty-bitty-rag's Introduction

Itty Bitty RAG

A tiny demonstration of a Retrieval Augmented Generation (RAG) system in TypeScript. The goal of this project is to demonstrate the bare bones of a RAG system. No attempts have been made to make this robust, efficient, or scalable.

LanceDB is used as the vector database. OpenAI is used for the embeddings (text-embedding-3-small) and generating responses (gpt-4o).

The example dataset provided is a collection of transcripts from the Lex Fridman Podcast generated using Deepgram. There are 119 transcripts in the dataset, and they are quite long, resulting in a total of approximately 4,052,586 tokens. See the section Indexing a subset of the data below if you want to run this faster on a subset of the data.

If you'd like to skip building the LanceDB database you can download it from here: ittybittyrag.lancedb.zip (26MB download, 42MB uncompressed). Just unzip it in the root directory of this project.

Usage

pnpm install

Add your OpenAI API key to .env:

OPENAI_API_KEY=sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Index the data:

pnpm run ingest

Do a search:

pnpm run search "What was said about physics?"

Indexing

The ingest.ts script ingests transcripts from the transcripts directory and indexes them in a LanceDB database.

  1. Load data
  2. Convert data to text
  3. Split text into chunks
  4. Create embeddings for each chunk
  5. Index embeddings in a vector database

Search

The search.ts script takes a query and searches the vector database for relevant chunks, addes them to the prompt context, and passes the prompt to the LLM.

  1. Take a query
  2. Generate an embedding for the query
  3. Retrieve relevant chunks from the vector database
  4. Feed the chunks into the LLM prompt
  5. Generate a response

Misc

Indexing a subset of the data

Edit the ingest.ts script to only index a subset of the data by changing this line:

for (const file of files) {

to this (substitute 10 for the number of files you want to index):

for (const file of files.slice(0, 10)) {

itty-bitty-rag's People

Contributors

pdlug avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.