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 🙏

© 2025 – Pkg Stats / Ryan Hefner

rag-module

v1.4.1

Published

A TypeScript/JavaScript module for implementing Retrieval-Augmented Generation (RAG) using Qdrant vector database, Google's Generative AI embeddings, and Groq LLM.

Readme

RAG Module Documentation

A TypeScript/JavaScript module for implementing Retrieval-Augmented Generation (RAG) using Qdrant vector database, Google's Generative AI embeddings, and Groq LLM.

Github Repo

Check out the Github Repository Link for this module here.

Features

  • Query classification using LLM
  • Vector storage and retrieval using Qdrant
  • Text embeddings using Google's Generative AI
  • Customizable prompts for classification and responses
  • Automatic text chunking and vector store creation
  • TypeScript support with full type definitions

Installation

npm install rag-module @qdrant/js-client-rest @langchain/google-genai groq-sdk langchain

Prerequisites

You'll need the following API keys:

  • Google API key for embeddings, Get it from here
  • Qdrant API key and URL for vector storage, Get it from your Database's Clusters Api Keys section.
  • Groq API key for LLM capabilities, Get it from here

Basic Usage

import { createRAG, RAGConfig } from 'rag-module';

const config: RAGConfig = {
    googleApiKey: 'your-google-api-key',
    qdrantUrl: 'your-qdrant-url',
    qdrantApiKey: 'your-qdrant-api-key',
    groqApiKey: 'your-groq-api-key',
    collectionName: 'custom-collection',
    fallbackResponse: 'Sorry, I could not find relevant information.'
};

const rag = createRAG(config);

async function main() {
    try {
        const result = await rag.processQuery(
            "Your context text here...",
            "Your query here..."
        );
        console.log('Response:', result.response);
        console.log('Category:', result.category);
    } catch (error) {
        console.error('Error:', error);
    }
}

Advanced Configuration

Custom Prompts

You can customize the classification and response prompts:

const config: RAGConfig = {
    // ... other config options
    prompts: {
        classification: `Analyze this query and categorize it as either 'technical', 'historical', 
                        or 'general': {query}. Reply with just one word.`,
        response: `Based on this context: '{context}', please answer this question: '{query}'.
                  Include relevant quotes when appropriate.`
    }
};

Configuration Options

| Option | Type | Required | Default | Description | |--------|------|----------|---------|-------------| | googleApiKey | string | Yes | - | Google API key for embeddings | | qdrantUrl | string | Yes | - | Qdrant server URL | | qdrantApiKey | string | Yes | - | Qdrant API key | | groqApiKey | string | Yes | - | Groq API key | | collectionName | string | No | 'default_collection' | Name of the Qdrant collection | | fallbackResponse | string | No | 'I could not find relevant information.' | Response when no relevant information is found | | prompts | object | No | See below | Custom prompts for classification and response |

Default Prompts

{
    classification: `I am providing you a query, based on the query your work is detect whether 
                    that is related to marks, events or general information. Query: {query}`,
    response: `You are a helpful assistant. Based on this context: "{context}", 
              please answer this question: "{query}"`
}

API Reference

createRAG(config: RAGConfig)

Creates a new RAG implementation instance with the provided configuration.

processQuery(contextText: string, query: string): Promise

Processes a query against the provided context and returns a response with classification.

Returns:

interface RAGResponse {
    response: string;  // The generated response
    category: string;  // The classified category
}

updatePrompts(newPrompts: Partial)

Updates the classification and response prompts after initialization.

Error Handling

The module throws errors for:

  • Missing required configuration parameters
  • Vector store creation failures
  • Query processing errors
  • Collection creation/management issues

TypeScript Support

The module includes TypeScript definitions for all exports. Import types as needed:

import { RAGConfig, RAGResponse } from 'rag-module';

Examples

Custom Classification Categories

const config: RAGConfig = {
    // ... other config options
    prompts: {
        classification: `Categorize as 'technical', 'historical', or 'general': {query}`,
        response: `Based on this context: '{context}', answer: '{query}'`
    }
};

const rag = createRAG(config);
const result = await rag.processQuery(
    "Technical documentation about TypeScript...",
    "What are TypeScript interfaces?"
);
// result.category will be 'technical'