Installation

First install the NodeJs package:

npm i @llm-tools/embedjs

Once you have installed the package, depending upon your preference you can either use:

Open Source Models

This section provides a quickstart example of using Llama3.2 as the Open source LLM and nomic-embed-text as the Open source embedding model.

These models are free and can be run locally using Ollama.

import { RAGApplicationBuilder } from '@llm-tools/embedjs';

import { OllamaEmbeddings, Ollama } from '@llm-tools/embedjs-ollama';

import { WebLoader } from '@llm-tools/embedjs-loader-web';

import { HNSWDb } from '@llm-tools/embedjs-hnswlib';



const ragApplication = await new RAGApplicationBuilder()

.setModel(new Ollama({ modelName: "llama3.2", baseUrl: 'http://localhost:11434' }))

.setEmbeddingModel(new OllamaEmbeddings({ model: 'nomic-embed-text', baseUrl: 'http://localhost:11434' }))

.setVectorDatabase(new HNSWDb())

.build();



await ragApplication.addLoader({ urlOrContent: 'https://www.forbes.com/profile/elon-musk' })

await ragApplication.addLoader({ urlOrContent: 'https://en.wikipedia.org/wiki/Elon_Musk' })



await ragApplication.query('What is the net worth of Elon Musk today?')

//Answer: The net worth of Elon Musk today is $258.7 billion.

You can also run these models using Huggingface. Read more about using Huggingface embeddings and LLMs with EmbedJs here and here.

In this section, we will use both an LLM and embedding model from OpenAI.

import { RAGApplicationBuilder, SIMPLE_MODELS } from '@llm-tools/embedjs';

import { OpenAiEmbeddings } from '@llm-tools/embedjs-openai';

import { WebLoader } from '@llm-tools/embedjs-loader-web';

import { HNSWDb } from '@llm-tools/embedjs-hnswlib';



//Replace this with your OpenAI key

process.env.OPENAI_API_KEY = "sk-xxxx"



const ragApplication = await new RAGApplicationBuilder()

.setModel(SIMPLE_MODELS.OPENAI_GPT4_O)

.setEmbeddingModel(new OpenAiEmbeddings())

.setVectorDatabase(new HNSWDb())

.build();



await ragApplication.addLoader(new WebLoader({ urlOrContent: 'https://www.forbes.com/profile/elon-musk' }));

await ragApplication.addLoader(new WebLoader({ urlOrContent: 'https://en.wikipedia.org/wiki/Elon_Musk' }));



await ragApplication.query('What is the net worth of Elon Musk today?')

//Answer: The net worth of Elon Musk today is $258.7 billion.

Next Steps

Now that you have created your first app, you can follow any of the links: