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 🙏

© 2026 – Pkg Stats / Ryan Hefner

lightrag-js

v1.0.4

Published

<div align="center"> <h1>LightRAG-JS</h1> <p><strong>The javascript version of <a href="https://github.com/HKUDS/LightRAG">LightRAG</a>, A lightweight and efficient retrieval enhanced generation framework </strong></p> </div>

Readme

🌬️ A implementation of LightRAG in js.

⚡ High fidelity from Python version.

Install

Install from npm

npm install lightrag-js

use in browser:

  • download the file lightrag.min.js from here
  • use it in your html file:
<script src="lightrag.min.js"></script>

the example is in the file here

Quick Start

Init LightRAG:

1. Nodejs

const rags = require("lightrag-js");
const lightRagConfig = require("../configs/config_node");

async function llm_model_func(
    prompt, options
) {
    const system_prompt = options?.system_prompt || '';
    const history_messages = options?.history_messages || [];
    const kwargs = options;
    return await rags.openAiCompleteIfCache(
        lightRagConfig.lightRagConfig['LLM_MODEL'],
        prompt,
        system_prompt,
        history_messages,
        lightRagConfig.lightRagConfig['LLM_BASE_API_URL'],
        lightRagConfig.lightRagConfig['LLM_API_KEY'],
        kwargs
    )
}

async function embedding_func(texts) {
    return await rags.openAiEmbedding(
        texts,
        lightRagConfig.lightRagConfig['EMBEDDING_MODEL_BASE_API_URL'],
        lightRagConfig.lightRagConfig['EMBEDDING_MODEL_API_KEY'],
        lightRagConfig.lightRagConfig['EMBEDDING_MODEL']

    )
}

async function loadJson(filePath) {
    try{
        const fs = require('fs')
        if (!fs.existsSync(filePath)) {
            fs.writeFileSync(filePath, '{}')
            return {}
        }
        const content = await fs.readFileSync(filePath,'utf-8');
        if (!content) return {}
        return JSON.parse(content)
    }catch(e){
        console.error(e)
        return {}
    }
}

async function writeJson(jsonObject, filePath) {
    try{
        const fs = require('fs')
        const jsonString = JSON.stringify(jsonObject, null, 2)
        fs.writeFileSync(filePath, jsonString)
    } catch (e) {
        console.error(e)
    }
}

2. ES6

import {
    LightRAG,
    createLightRAG,
    embeddingFunc,
    llmModelFunc,
    openAiCompleteIfCache,
    openAiEmbedding
} from "lightrag-js"
import { lightRagConfig } from "../rag/config";
import { loadJson, writeJson } from "../rag/utils";
async function llm_model_func(
    prompt: string, options: any
) {
    const system_prompt = options?.system_prompt || '';
    const history_messages = options?.history_messages || [];
    const kwargs = options;
    return await openAiCompleteIfCache(
        lightRagConfig['LLM_MODEL'],
        prompt,
        system_prompt,
        history_messages,
        lightRagConfig['LLM_BASE_API_URL'],
        lightRagConfig['LLM_API_KEY'],
        kwargs
    )
}

async function embedding_func(texts: string[]) {
    return await openAiEmbedding(
        texts,
        lightRagConfig['EMBEDDING_MODEL_BASE_API_URL'],
        lightRagConfig['EMBEDDING_MODEL_API_KEY'],
        lightRagConfig['EMBEDDING_MODEL']
    )
}

async function _loadJson(filePath: string) {
    //TODO
}

async function _writeJson(jsonObject: Record<string, any>, filePath: string) {
    //TODO
}

async function getRag() {
    const rag = await (createLightRAG(
        {
            workingDir: lightRagConfig['RAG_DIR'],
            llmModelFunc: new llmModelFunc(llm_model_func),
            embeddingFunc: new embeddingFunc(
                3072,
                lightRagConfig['EMBEDDING_MAX_TOKEN_SIZE'],
                embedding_func,
            ),
            loadJsonFunc: loadJson,
            writeJsonFunc: writeJson,
        }
    ))
    return rag
}

getRag().then(rag => {
    console.log(rag)
})

../configs/config_node.js

 const lightRagConfig = {
    "RAG_DIR": "",
    "LLM_MODEL": "deepseek-chat",
    "LLM_API_KEY": "",
    "LLM_BASE_API_URL": "https://api.deepseek.com",
    "EMBEDDING_MODEL": "text-embedding-v1",
    "EMBEDDING_MAX_TOKEN_SIZE": 8192,
    "EMBEDDING_MODEL_API_KEY": "",
    "EMBEDDING_MODEL_BASE_API_URL": "",
}

// Nodejs
module.exports = {
    lightRagConfig
}

// ES6
export { lightRagConfig }

You can add any fields to a data. But there are two keywords:

  • __id__: If passed, NanoVectorDB will use your id, otherwise a generated id will be used.
  • __vector__: must pass, your embedding type is Float32Array.

Query Param

// Nodejs
async function testQuery(mode, content, rag) {
    const param = new rags.QueryParam()
    param.mode = mode
    rag.query(content, param)
}
//ES6
async function testQuery(mode, content, rag) {
    const param = new QueryParam()
    param.mode = mode
    rag.query(content, param)
}

//
const content = "What is the highest peak in the World?"
testQuery("hybrid", content, rag)

流式响应

const content = "你好"
const param = new rags.QueryParam()
param.mode = mode
param.isStreamResponse = true
console.log(param)
let res = ""
const stream = await rag.query(content, param)
for await (chunk of stream) {
    console.log(chunk)
    res += chunk
}
console.log("res", res)
console.log("stream", stream)

Insert

const content = "The Himalayas are the highest peak in the world."
rag.insert(content)

get insert progress

  rag.getRagProgress()
  
  /**
   * @return RagProcess
   */
  // interface RagProcess {
  // totalInsertChunks: number;
  // readyInsertChunks: number;
  // isInsertReady: boolean;
  // isQueryReady: boolean;
  // }

Delete

const content = "Himalayas"
rag.deleteByEntity(content)

Get Knowledge Graph HTML

const fs = require('fs')
const khtml = rag.getKnowledgeHtml()
const savePath = "knowledge.html"
fs.writeFileSync(savePath, khtml)

This will generate a html file, you can open it in your browser.

Thanks