npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@forge-ml/rag

v0.0.17

Published

A RAG (Retrieval-Augmented Generation) package for Forge ML

Downloads

10

Readme

Forge RAG (Retrieval-Augmented Generation) Package

Overview

This package provides a flexible and efficient implementation of Retrieval-Augmented Generation (RAG) for Node.js applications. It offers tools for document chunking, embedding generation, vector storage, and similarity search, enabling developers to build powerful RAG systems.

Features

  • Document chunking with various strategies
  • Embedding generation using OpenAI or Nomic AI
  • Vector storage and retrieval using Redis
  • Flexible querying and similarity search
  • Utility functions for text preprocessing and token estimation

Installation

npm install @forge-ml/rag

Quick Start

import { createRagger, OpenAIEmbedder, RedisVectorStore } from "@forge-ml/rag";

const embedder = new OpenAIEmbedder({ apiKey: "your-openai-api-key" });
const vectorStore = new RedisVectorStore("redis://localhost:6379");

const ragger = createRagger(embedder, vectorStore);

// Initialize a document
const chunks = await ragger.initializeDocument("Your document text here");

// Query the document
const results = await ragger.query("Your query here");

Core Components

Embedder

The package supports two embedding providers:

  1. OpenAI Embedder
const embedder = new OpenAIEmbedder({
  type: "openai",
  apiKey: process.env.OPENAI_API_KEY,
});
  1. Nomic Embedder
const embedder = new NomicEmbedder({
  type: "nomic",
  apiKey: process.env.NOMIC_API_KEY,
});

Vector Store

The package uses Redis as the vector store:

const vectorStore = new RedisVectorStore(process.env.REDIS_URL);

API Reference

createRagger(embedder: Embedder, vectorStore: VectorStore)

Creates a new RAG instance with the specified embedder and vector store.

ragger.initializeDocument(text: string, options?: InitializeDocumentOptions)

Chunks the input text and stores the embeddings in the vector store.

ragger.query(query: string)

Performs a similarity search based on the input query and returns relevant chunks.

Configuration

Redis Setup

To set up the Redis vector store, use the provided Docker Compose file:

version: '3.8'

services:
  redis:
    image: redis/redis-stack:latest
    container_name: redis
    ports:
      - "6379:6379"
    volumes:
      - redis_data:/data
    command: >
      redis-server
      --appendonly yes
      --protected-mode no
      --loadmodule /opt/redis-stack/lib/redisearch.so
      --loadmodule /opt/redis-stack/lib/rejson.so
    restart: always

volumes:
  redis_data:
    driver: local

Run the following script to start the Redis container:

#!/bin/bash

# Function to check if Docker is running
check_docker() {
    if ! docker info > /dev/null 2>&1; then
        echo "Docker is not running. Please start Docker and try again."
        exit 1
    fi
}

# Function to spin up the vector store
spin_up_vector_store() {
    echo "Spinning up the vector store..."
    docker compose -f docker/redis.yml up -d
    if [ $? -eq 0 ]; then
        echo "Vector store is now running."
    else
        echo "Failed to start the vector store. Please check the Docker logs for more information."
        exit 1
    fi
}

# Main execution
check_docker
spin_up_vector_store

Contributing

Contributions are welcome! Please refer to the CONTRIBUTING.md file for guidelines.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments

  • OpenAI for their embedding API
  • Nomic AI for their embedding capabilities
  • Redis for providing an efficient vector store solution