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.
Copy
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.
Copy
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 keyprocess.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.