# π addLoader
Source: https://llm-tools.mintlify.app/api-reference/methods/add-loader
The `addLoader()` method is used to load the data sources from different data sources to a RAG pipeline. You can find the signature below:
### Parameters
The data to embed, can be a URL, local file or raw content, depending on the data type.. You can find the full list of supported data sources [here](/components/data-sources/overview).
## Usage
### Load data from webpage
```ts Code example theme={null}
import { RAGApplicationBuilder } from '@llm-tools/embedjs';
import { OpenAiEmbeddings } from '@llm-tools/embedjs-openai';
import { HNSWDb } from '@llm-tools/embedjs-hnswlib';
import { WebLoader } from '@llm-tools/embedjs-loader-web';
const app = await new RAGApplicationBuilder()
.setModel(SIMPLE_MODELS.OPENAI_GPT4_O)
.setEmbeddingModel(new OpenAiEmbeddings())
.setVectorDatabase(new HNSWDb())
.build();
await app.addLoader(new WebLoader({ urlOrContent: 'https://www.forbes.com/profile/elon-musk' }));
//Add loader completed with 4 new entries for 6c8d1a7b-ea34-4927-8823-xba29dcfc5ac
```
### Load data from sitemap
```ts Code example theme={null}
import { RAGApplicationBuilder } from '@llm-tools/embedjs';
import { OpenAiEmbeddings } from '@llm-tools/embedjs-openai';
import { HNSWDb } from '@llm-tools/embedjs-hnswlib';
import { SitemapLoader } from '@llm-tools/embedjs-loader-sitemap';
const app = await new RAGApplicationBuilder()
.setModel(SIMPLE_MODELS.OPENAI_GPT4_O)
.setEmbeddingModel(new OpenAiEmbeddings())
.setVectorDatabase(new HNSWDb())
.build();
await app.addLoader(new SitemapLoader({ url: '"https://js.langchain.com/sitemap.xml' }));
//Add loader completed with 11024 new entries for 6c8d1a7b-ea34-4927-8823-xba29dcfc5ad
```
You can find complete list of supported data sources [here](/components/data-sources/overview).
# π deleteConversation
Source: https://llm-tools.mintlify.app/api-reference/methods/delete-conversation
The `deleteConversation()` method allows you to delete a particular conversation thread from the database
### Parameters
The conversationId that you want to delete.
If you want to delete the conversations stored when there were no conversation ids passed, pass in 'default'
### Usage
```ts theme={null}
import 'dotenv/config';
import path from 'node:path';
import { RAGApplicationBuilder, SIMPLE_MODELS } from '@llm-tools/embedjs';
import { LibSqlDb, LibSqlStore } from '@llm-tools/embedjs-libsql';
import { OpenAiEmbeddings } from '@llm-tools/embedjs-openai';
import { WebLoader } from '@llm-tools/embedjs-loader-web';
const databasePath = path.resolve('./examples/libsql/data.db');
const ragApplication = await new RAGApplicationBuilder()
.setStore(new LibSqlStore({ path: databasePath }))
.setVectorDatabase(new LibSqlDb({ path: databasePath }))
.setEmbeddingModel(new OpenAiEmbeddings())
.setModel(SIMPLE_MODELS.OPENAI_GPT4_O)
.build();
await ragApplication.addLoader(new WebLoader({ urlOrContent: 'https://en.wikipedia.org/wiki/Elon_Musk' }));
console.log(await ragApplication.query('Was Elon Musk the founder of Tesla originally?'));
console.log(await ragApplication.query('What is the net worth of Elon Musk today?'));
await app.deleteConversation('default');
```
# π deleteLoader
Source: https://llm-tools.mintlify.app/api-reference/methods/delete-loader
The `deleteLoader()` method allows you to delete the data loaded by a loader previously added to the app.
### Parameters
The loader unique id that is generated when the loader is added to the app.
### Usage
```ts theme={null}
import { RAGApplicationBuilder } from '@llm-tools/embedjs';
import { OpenAiEmbeddings } from '@llm-tools/embedjs-openai';
import { HNSWDb } from '@llm-tools/embedjs-hnswlib';
import { RedisStore } from '@llm-tools/embedjs-redis';
import { WebLoader } from '@llm-tools/embedjs-loader-web';
import { SitemapLoader } from '@llm-tools/embedjs-loader-sitemap';
const app = await new RAGApplicationBuilder()
.setModel(SIMPLE_MODELS.OPENAI_GPT4_O)
.setEmbeddingModel(new OpenAiEmbeddings())
.setVectorDatabase(new HNSWDb())
.setStore(
new RedisStore({
host: this.configService.get('REDIS_HOST'),
port: this.configService.get('REDIS_PORT'),
password: this.configService.get('REDIS_PASSWORD'),
}),
)
.build();
const { uniqueId: forbesId } = await app.addLoader(new WebLoader({ urlOrContent: 'https://www.forbes.com/profile/elon-musk' }));
const { uniqueId: sitemapId } = await app.addLoader(new SitemapLoader({ url: '"https://js.langchain.com/sitemap.xml' }));
await app.deleteLoader(forbesId);
```
If you do not have the uniqueId, you can use `app.getLoaders()` method to get all the loaders and extract the `uniqueId` from it.
# π getLoaders
Source: https://llm-tools.mintlify.app/api-reference/methods/get-loaders
The `getLoaders()` method returns a list of all the data sources / loaders added so far.
This data comes from the store and if the store is inMemory, then the list will not include the loaders from before the restart.
### Usage
```ts theme={null}
import { RAGApplicationBuilder } from '@llm-tools/embedjs';
import { OpenAiEmbeddings } from '@llm-tools/embedjs-openai';
import { HNSWDb } from '@llm-tools/embedjs-hnswlib';
import { RedisStore } from '@llm-tools/embedjs-redis';
import { WebLoader } from '@llm-tools/embedjs-loader-web';
import { SitemapLoader } from '@llm-tools/embedjs-loader-sitemap';
const app = await new RAGApplicationBuilder()
.setModel(SIMPLE_MODELS.OPENAI_GPT4_O)
.setEmbeddingModel(new OpenAiEmbeddings())
.setVectorDatabase(new HNSWDb())
.setStore(
new RedisStore({
host: this.configService.get('REDIS_HOST'),
port: this.configService.get('REDIS_PORT'),
password: this.configService.get('REDIS_PASSWORD'),
}),
)
.build();
await app.addLoader(new WebLoader({ urlOrContent: 'https://www.forbes.com/profile/elon-musk' }));
await app.addLoader(new SitemapLoader({ url: '"https://js.langchain.com/sitemap.xml' }));
console.log(await app.getLoaders())
/*
[
{
"uniqueId": "6c8d1a7b-ea34-4927-8823-xba29dcfc5ac",
"type": "WebLoader",
loaderMetadata: {
urlOrContent: "https://www.forbes.com/profile/elon-musk"
}
},
{
"uniqueId": "6c8d1a7b-ea34-4927-8823-xba29dcfc5ad",
"type": "SitemapLoader",
loaderMetadata: {
url: "https://www.forbes.com/profile/elon-musk"
}
}
]
*/
```
# β query
Source: https://llm-tools.mintlify.app/api-reference/methods/query
The `.query()` method empowers developers to ask questions and receive relevant answers through a user-friendly query API.
Function signature is given below:
### Parameters
Question to ask
The conversation ID to which the query belongs in case this is a chatbot scenario
In case you want to pass along your own context information. Passing this parameter disables the default context generation.
The context text that is passed to the LLM
The metadata that is passed to EmbedJs
Unique identifier for the bit of information
The unique identifier for the group of information bits
The source string returned if this piece of info was used by the LLM
### Returns
Unique identifier for the query response in a conversation
Unique identifier for the query response in a conversation
Unique identifier for the query response in a conversation
The individual sources that were used to generate the answer
Unique identifier for the loader
The source of the information
The number of tokens used to answer the query
The number of input tokens used to process the query
The number of output tokens used to process the query
## Usage
If you want to get the answer to question and return both answer and citations, use the following code snippet:
```ts Code Example theme={null}
import { RAGApplicationBuilder } from '@llm-tools/embedjs';
import { OllamaEmbeddings } 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();
ragApplication.addLoader({ urlOrContent: 'https://www.forbes.com/profile/elon-musk' })
ragApplication.addLoader({ urlOrContent: 'https://en.wikipedia.org/wiki/Elon_Musk' })
await ragApplication.query('What is the net worth of Elon Musk today?')
await ragApplication.query('Who is Elon Musk?' { conversationId: '1' })
/*
*/
```
# π reset
Source: https://llm-tools.mintlify.app/api-reference/methods/reset
The `reset()` method allows you to wipe the data from your RAG application and start from scratch.
## Usage
```ts Code example theme={null}
import { RAGApplicationBuilder } from '@llm-tools/embedjs';
import { OpenAiEmbeddings } from '@llm-tools/embedjs-openai';
import { HNSWDb } from '@llm-tools/embedjs-hnswlib';
import { WebLoader } from '@llm-tools/embedjs-loader-web';
const app = await new RAGApplicationBuilder()
.setModel(SIMPLE_MODELS.OPENAI_GPT4_O)
.setEmbeddingModel(new OpenAiEmbeddings())
.setVectorDatabase(new HNSWDb())
.build();
await app.reset();
```
# π search
Source: https://llm-tools.mintlify.app/api-reference/methods/search
The `.search()` enables you to uncover the most pertinent context by performing a semantic search across your data sources based on a given query.
Refer to the function signature below:
### Parameters
Question
### Returns
The list of relevant information
The context text that is passed to the LLM
The metadata that was passed to EmbedJs
Unique identifier for the bit of information
The unique identifier for the group of information bits
The source string
## Usage
Refer to the following example on how to use the search api:
```ts Code example theme={null}
import { RAGApplicationBuilder } from '@llm-tools/embedjs';
import { OllamaEmbeddings } from '@llm-tools/embedjs-ollama';
import { WebLoader } from '@llm-tools/embedjs-loader-web';
import { HNSWDb } from '@llm-tools/embedjs-hnswlib';
import { SitemapLoader } from '@llm-tools/embedjs-loader-sitemap';
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();
//Add Next.JS Website and docs
app.addLoader(new SitemapLoader({ url: "https://nextjs.org/sitemap.xml" }))
app.search("Summarize the features of Next.js 14?")
/*[
{
'score': 0.99,
'pageContent': 'Next.js 14 | Next.jsBack to BlogThursday, October 26th 2023Next.js 14Posted byLee Robinson@leeerobTim Neutkens@timneutkensAs we announced at Next.js Conf, Next.js 14 is our most focused release with: Turbopack: 5,000 tests passing for App & Pages Router 53% faster local server startup 94% faster code updates with Fast Refresh Server Actions (Stable): Progressively enhanced mutations Integrated with caching & revalidating Simple function calls, or works natively with forms Partial Prerendering',
'metadata': {
'id': '6c8d1a7b-ea34-4927-8823-daa29dcfc5af',
'uniqueLoaderId': '6c8d1a7b-ea34-4927-8823-xba29dcfc5ac',
'source': 'https://nextjs.org/blog/next-14'
}
},
{
'score': 0.98,
'pageContent': 'Next.js 13.3 | Next.jsBack to BlogThursday, April 6th 2023Next.js 13.3Posted byDelba de Oliveira@delba_oliveiraTim Neutkens@timneutkensNext.js 13.3 adds popular community-requested features, including: File-Based Metadata API: Dynamically generate sitemaps, robots, favicons, and more. Dynamic Open Graph Images: Generate OG images using JSX, HTML, and CSS. Static Export for App Router: Static / Single-Page Application (SPA) support for Server Components. Parallel Routes and Interception: Advanced',
'metadata': {
'id': '6c8d1a7b-ea34-4927-8823-daa29dcfc5a1',
'uniqueLoaderId': '6c8d1a7b-ea34-4927-8823-xba29dcfc5ae',
'source': 'https://nextjs.org/blog/next-13-3'
}
},
{
'score': 0.98,
'pageContent': 'Upgrading: Version 14 | Next.js MenuUsing App RouterFeatures available in /appApp Router.UpgradingVersion 14Version 14 Upgrading from 13 to 14 To update to Next.js version 14, run the following command using your preferred package manager: Terminalnpm i next@latest react@latest react-dom@latest eslint-config-next@latest Terminalyarn add next@latest react@latest react-dom@latest eslint-config-next@latest Terminalpnpm up next react react-dom eslint-config-next -latest Terminalbun add next@latest',
'metadata': {
'id': '6c8d1a7b-ea34-4927-8823-daa29dcfc5a2',
'uniqueLoaderId': '6c8d1a7b-ea34-4927-8823-xba29dcfc5ad',
'source': 'https://nextjs.org/docs/app/building-your-application/upgrading/version-14'
}
}
]*/
```
# RAGApplicationBuilder
Source: https://llm-tools.mintlify.app/api-reference/overview
Create a EmbedJs `RAGApplication` using `RAGApplicationBuilder`. `RAGApplication` is the main entrypoint for a developer to interact with EmbedJs APIs.
`RAGApplicationBuilder` configures the LLM, vector database and embedding model of your choice and return a `RAGApplication` at the end.
### Attributes
This configures the LLM for the RAG application. Setting `NO_MODEL` will not load any LLM - in this case, you can only use semantic search and there will be no no LLM powered Q\&A.
`SIMPLE_MODELS` are predefined models with sane defaults available in EmbedJs.
All predefined models inherit from `BaseModel`. You can therefore pass a custom model that extends `BaseModel` / provide a custom set of parameters for a predefined model.
For a list of predefined LLMs, refer the section on [LLMs](/components/llms).
This configures the embedding model for use with the RAG application. Embedding models are used to convert text into vectors.
For a list of predefined embedding models, refer the section on [embedding models](/components/embedding-models).
This configures the vector database to be used with RAG application.
For a list of available vector databases, refer the section on [vector databases](/components/vector-databases).
This configures a stores that is used internally by the appliation to keep track of what sources and data have been previously processed.
Previously processed data is not reprocessed - thus removing the need for this logic to be implemented at your end.
If this is not provided, the application will maintain this data in memorywhich will be lost on app restart.
For a list of built-in stores, refer the section on [stores](/components/stores).
This configures a temperature to be used with the LLM. This controls the randomness of the LLM output.
By default, the application sets the temperature to 0.1.
This parameter is used to control what amounts to a relevant / contextual document when retrieving documents from the vector database.
Documents below this cut off are not discarded. EmbedJs uses sane defaults for this parameter but you can customize.
This allows you to customize the system message used when querying the LLM. The system message is included once with every call to the LLM besides the user query and chat history.
## Usage
```ts Code Example theme={null}
import { RAGApplicationBuilder } from '@llm-tools/embedjs';
import { OpenAiEmbeddings } from '@llm-tools/embedjs-openai';
import { HNSWDb } from '@llm-tools/embedjs-hnswlib';
//app is of type RAGApplication
const app = await new RAGApplicationBuilder()
.setModel(SIMPLE_MODELS.OPENAI_GPT4_O)
.setEmbeddingModel(new OpenAiEmbeddings())
.setVectorDatabase(new HNSWDb())
.build();
```
# π Confluence
Source: https://llm-tools.mintlify.app/components/data-sources/confluence
You can load all pages from a Confluence space using the `ConfluenceLoader`.
## Install Confluence addon
```bash theme={null}
npm install @llm-tools/embedjs-loader-confluence
```
## Usage
```ts theme={null}
import { RAGApplicationBuilder } from '@llm-tools/embedjs';
import { OpenAiEmbeddings } from '@llm-tools/embedjs-openai';
import { HNSWDb } from '@llm-tools/embedjs-hnswlib';
import { ConfluenceLoader } from '@llm-tools/embedjs-loader-confluence';
const app = await new RAGApplicationBuilder()
.setModel(SIMPLE_MODELS.OPENAI_GPT4_O)
.setEmbeddingModel(new OpenAiEmbeddings())
.setVectorDatabase(new HNSWDb())
.build();
app.addLoader(new ConfluenceLoader({ spaceNames: ['...', '...'], confluenceEmail: '...', confluenceToken: '...' }))
```
# π CSV
Source: https://llm-tools.mintlify.app/components/data-sources/csv
You can load any csv file from your local file system or through a URL.
Headers are included for each line, so if you have an `age` column, `18` will be added as `age: 18`.
## Install CSV addon
```bash theme={null}
npm install @llm-tools/embedjs-loader-csv
```
## Usage
### Load from a local file
```ts theme={null}
import { RAGApplicationBuilder } from '@llm-tools/embedjs';
import { OpenAiEmbeddings } from '@llm-tools/embedjs-openai';
import { HNSWDb } from '@llm-tools/embedjs-hnswlib';
import { CsvLoader } from '@llm-tools/embedjs-loader-csv';
const app = await new RAGApplicationBuilder()
.setModel(SIMPLE_MODELS.OPENAI_GPT4_O)
.setEmbeddingModel(new OpenAiEmbeddings())
.setVectorDatabase(new HNSWDb())
.build();
app.addLoader(new CsvLoader({ filePathOrUrl: '/path/to/file.csv' }))
```
### Load from URL
```ts theme={null}
import { RAGApplicationBuilder } from '@llm-tools/embedjs';
import { OpenAiEmbeddings } from '@llm-tools/embedjs-openai';
import { HNSWDb } from '@llm-tools/embedjs-hnswlib';
import { CsvLoader } from '@llm-tools/embedjs-loader-csv';
const app = await new RAGApplicationBuilder()
.setModel(SIMPLE_MODELS.OPENAI_GPT4_O)
.setEmbeddingModel(new OpenAiEmbeddings())
.setVectorDatabase(new HNSWDb())
.build();
app.addLoader(new CsvLoader({ filePathOrUrl: 'https://people.sc.fsu.edu/~jburkardt/data/csv/airtravel.csv' }))
```
# βοΈ Custom
Source: https://llm-tools.mintlify.app/components/data-sources/custom
You can load any data from your own custom data source by implementing the `BaseLoader` interface. For example -
```ts theme={null}
class CustomLoader extends BaseLoader<{ customChunkMetadata: string }> {
constructor() {
super('uniqueId');
}
async *getChunks() {
throw new Error('Method not implemented.');
}
}
```
### Customizing the chunk size and overlap
If you want to customize the chunk size or the chunk overlap on an existing loader, all built-in loaders take an additional parameter `chunkSize` and `chunkOverlap`
in their constructor. For example -
```ts theme={null}
import { RAGApplicationBuilder } from '@llm-tools/embedjs';
import { OpenAiEmbeddings } from '@llm-tools/embedjs-openai';
import { HNSWDb } from '@llm-tools/embedjs-hnswlib';
import { DocxLoader } from '@llm-tools/embedjs-loader-msoffice';
const app = await new RAGApplicationBuilder()
.setModel(SIMPLE_MODELS.OPENAI_GPT4_O)
.setEmbeddingModel(new OpenAiEmbeddings())
.setVectorDatabase(new HNSWDb())
.build();
app.addLoader(new DocxLoader({ filePathOrUrl: '...', chunkOverlap: 100, chunkSize: 20 }))
```
# π Directory/Folder
Source: https://llm-tools.mintlify.app/components/data-sources/directory
To use an entire directory as data source, just use `LocalPathLoader` and pass in the path of the local directory.
This loader automatically reads all the files in the directory and its subdirectories. If you pass the path to a single file, only that file will be read.
## Usage
```ts theme={null}
import { RAGApplicationBuilder, LocalPathLoader } from '@llm-tools/embedjs';
import { OpenAiEmbeddings } from '@llm-tools/embedjs-openai';
import { HNSWDb } from '@llm-tools/embedjs-hnswlib';
const app = await new RAGApplicationBuilder()
.setModel(SIMPLE_MODELS.OPENAI_GPT4_O)
.setEmbeddingModel(new OpenAiEmbeddings())
.setVectorDatabase(new HNSWDb())
.build();
app.addLoader(new LocalPathLoader({ path: '...' }))
```
You need to have installed the neccessaty loaders to process the expected file types in the directory for the application to be able to process that file type.
# π DOCX file
Source: https://llm-tools.mintlify.app/components/data-sources/docx
You can load any docx file from your local file system or through a URL.
## Install MSOffice addon
```bash theme={null}
npm install @llm-tools/embedjs-loader-msoffice
```
## Usage
```ts theme={null}
import { RAGApplicationBuilder } from '@llm-tools/embedjs';
import { OpenAiEmbeddings } from '@llm-tools/embedjs-openai';
import { HNSWDb } from '@llm-tools/embedjs-hnswlib';
import { DocxLoader } from '@llm-tools/embedjs-loader-msoffice';
const app = await new RAGApplicationBuilder()
.setModel(SIMPLE_MODELS.OPENAI_GPT4_O)
.setEmbeddingModel(new OpenAiEmbeddings())
.setVectorDatabase(new HNSWDb())
.build();
app.addLoader(new DocxLoader({ filePathOrUrl: '...' }))
```
# π Excel file
Source: https://llm-tools.mintlify.app/components/data-sources/excel
You can load any xlsx file from your local file system or through a URL.
## Install MSOffice addon
```bash theme={null}
npm install @llm-tools/embedjs-loader-msoffice
```
## Usage
```ts theme={null}
import { RAGApplicationBuilder } from '@llm-tools/embedjs';
import { OpenAiEmbeddings } from '@llm-tools/embedjs-openai';
import { HNSWDb } from '@llm-tools/embedjs-hnswlib';
import { ExcelLoader } from '@llm-tools/embedjs-loader-msoffice';
const app = await new RAGApplicationBuilder()
.setModel(SIMPLE_MODELS.OPENAI_GPT4_O)
.setEmbeddingModel(new OpenAiEmbeddings())
.setVectorDatabase(new HNSWDb())
.build();
app.addLoader(new ExcelLoader({ filePathOrUrl: '...' }))
```
# πΌοΈ Image
Source: https://llm-tools.mintlify.app/components/data-sources/image
You can load most images using an LLM to describe the contents of the image. This LLM by default is the one used with the application,
but a special LLM can also be specified for the content description. To load images, follow the steps below.
## Install Image addon
```bash theme={null}
npm install @llm-tools/embedjs-loader-image
```
## Usage
### Load from a local file
```ts theme={null}
import { RAGApplicationBuilder } from '@llm-tools/embedjs';
import { ImageLoader } from '@llm-tools/embedjs-loader-image';
import { OpenAiEmbeddings } from '@llm-tools/embedjs-openai';
import { HNSWDb } from '@llm-tools/embedjs-hnswlib';
const app = await new RAGApplicationBuilder()
.setModel(SIMPLE_MODELS.OPENAI_GPT4_O)
.setEmbeddingModel(new OpenAiEmbeddings())
.setVectorDatabase(new HNSWDb())
.build();
app.addLoader(new ImageLoader({ filePathOrUrl: '/path/to/file.jpeg' }))
```
# π JSON
Source: https://llm-tools.mintlify.app/components/data-sources/json
To add any json file, use the `JsonLoader`.
Headers are included for each line, so for example if you have a json like `{"age": 18}`, then it will be added as `age: 18`.
## Usage
```ts Example theme={null}
import { RAGApplicationBuilder, JsonLoader } from '@llm-tools/embedjs';
import { OpenAiEmbeddings } from '@llm-tools/embedjs-openai';
import { HNSWDb } from '@llm-tools/embedjs-hnswlib';
const app = await new RAGApplicationBuilder()
.setModel(SIMPLE_MODELS.OPENAI_GPT4_O)
.setEmbeddingModel(new OpenAiEmbeddings())
.setVectorDatabase(new HNSWDb())
.build();
app.addLoader(new JsonLoader({ object: {...} }))
```
# π Markdown / MDX file
Source: https://llm-tools.mintlify.app/components/data-sources/markdown
You can load any Markdown(MD) or MDX file from your local file system or through a URL.
## Install Markdown addon
```bash theme={null}
npm install @llm-tools/embedjs-loader-markdown
```
## Usage
```ts theme={null}
import { RAGApplicationBuilder } from '@llm-tools/embedjs';
import { OpenAiEmbeddings } from '@llm-tools/embedjs-openai';
import { HNSWDb } from '@llm-tools/embedjs-hnswlib';
import { MarkdownLoader } from '@llm-tools/embedjs-loader-markdown';
const app = await new RAGApplicationBuilder()
.setModel(SIMPLE_MODELS.OPENAI_GPT4_O)
.setEmbeddingModel(new OpenAiEmbeddings())
.setVectorDatabase(new HNSWDb())
.build();
app.addLoader(new MarkdownLoader({ filePathOrUrl: '...' }))
```
# Overview
Source: https://llm-tools.mintlify.app/components/data-sources/overview
EmbedJs comes with built-in support for various data sources.
We handle the complexity of loading unstructured data from these data sources, allowing you to easily customize your app through a user-friendly interface.
# π° PDF
Source: https://llm-tools.mintlify.app/components/data-sources/pdf
You can load any pdf file from your local file system or through a URL.
## Install PDF addon
```bash theme={null}
npm install @llm-tools/embedjs-loader-pdf
```
## Usage
### Load from a local file
```ts theme={null}
import { RAGApplicationBuilder } from '@llm-tools/embedjs';
import { OpenAiEmbeddings } from '@llm-tools/embedjs-openai';
import { HNSWDb } from '@llm-tools/embedjs-hnswlib';
import { PdfLoader } from '@llm-tools/embedjs-loader-pdf';
const app = await new RAGApplicationBuilder()
.setModel(SIMPLE_MODELS.OPENAI_GPT4_O)
.setEmbeddingModel(new OpenAiEmbeddings())
.setVectorDatabase(new HNSWDb())
.build();
app.addLoader(new PdfLoader({ filePathOrUrl: '/path/to/file.pdf' }))
```
### Load from URL
```ts theme={null}
import { RAGApplicationBuilder } from '@llm-tools/embedjs';
import { OpenAiEmbeddings } from '@llm-tools/embedjs-openai';
import { HNSWDb } from '@llm-tools/embedjs-hnswlib';
import { PdfLoader } from '@llm-tools/embedjs-loader-pdf';
const app = await new RAGApplicationBuilder()
.setModel(SIMPLE_MODELS.OPENAI_GPT4_O)
.setEmbeddingModel(new OpenAiEmbeddings())
.setVectorDatabase(new HNSWDb())
.build();
await app.addLoader(new PdfLoader({ filePathOrUrl: 'https://arxiv.org/pdf/1706.03762.pdf' }))
await app.query("What is the paper 'attention is all you need' about?");
```
Note that we do not support password protected pdf files.
# π PPT file
Source: https://llm-tools.mintlify.app/components/data-sources/ppt
You can load any pptx file from your local file system or through a URL.
## Install MSOffice addon
```bash theme={null}
npm install @llm-tools/embedjs-loader-msoffice
```
## Usage
```ts theme={null}
import { RAGApplicationBuilder } from '@llm-tools/embedjs';
import { OpenAiEmbeddings } from '@llm-tools/embedjs-openai';
import { HNSWDb } from '@llm-tools/embedjs-hnswlib';
import { PptLoader } from '@llm-tools/embedjs-loader-msoffice';
const app = await new RAGApplicationBuilder()
.setModel(SIMPLE_MODELS.OPENAI_GPT4_O)
.setEmbeddingModel(new OpenAiEmbeddings())
.setVectorDatabase(new HNSWDb())
.build();
app.addLoader(new LocalPathLoader({ filePathOrUrl: '...' }))
```
# πΊοΈ Sitemap
Source: https://llm-tools.mintlify.app/components/data-sources/sitemap
Add all web pages from an xml-sitemap use the `SitemapLoader`.
## Install Sitemap addon
```bash theme={null}
npm install @llm-tools/embedjs-loader-sitemap
```
## Usage
```ts theme={null}
import { RAGApplicationBuilder } from '@llm-tools/embedjs';
import { OpenAiEmbeddings } from '@llm-tools/embedjs-openai';
import { HNSWDb } from '@llm-tools/embedjs-hnswlib';
import { SitemapLoader } from '@llm-tools/embedjs-loader-sitemap';
const app = await new RAGApplicationBuilder()
.setModel(SIMPLE_MODELS.OPENAI_GPT4_O)
.setEmbeddingModel(new OpenAiEmbeddings())
.setVectorDatabase(new HNSWDb())
.build();
app.addLoader(new SitemapLoader({ url: '...' }))
```
# π Text
Source: https://llm-tools.mintlify.app/components/data-sources/text
Text is a local data type. To supply your own text, use the `TextLoader` and enter a string. The text is not processed, this can be very versatile.
## Usage
```ts theme={null}
import { RAGApplicationBuilder, TextLoader } from '@llm-tools/embedjs';
import { OpenAiEmbeddings } from '@llm-tools/embedjs-openai';
import { HNSWDb } from '@llm-tools/embedjs-hnswlib';
const app = await new RAGApplicationBuilder()
.setModel(SIMPLE_MODELS.OPENAI_GPT4_O)
.setEmbeddingModel(new OpenAiEmbeddings())
.setVectorDatabase(new HNSWDb())
.build();
app.addLoader(new TextLoader({ text: '...' }))
```
# π¬ TwelveLabs Video
Source: https://llm-tools.mintlify.app/components/data-sources/twelvelabs-video
To add any video to your app, use the `TwelveLabsVideoLoader`. It analyses the video with the [TwelveLabs](https://twelvelabs.io) Pegasus video understanding model β which watches the visuals, motion and audio β and loads the resulting description into your RAG application. This lets you run RAG over video content directly from a public URL, without a separate transcription step.
* Sign up for an account with TwelveLabs and grab an API key. There's a generous free tier at [twelvelabs.io](https://twelvelabs.io).
* Set the key in the environment variable `TWELVELABS_API_KEY` (or pass it directly to the loader).
```bash theme={null}
TWELVELABS_API_KEY=""
```
## Install TwelveLabs addon
```bash theme={null}
npm install @llm-tools/embedjs-twelvelabs
```
## Usage
```ts theme={null}
import { RAGApplicationBuilder } from '@llm-tools/embedjs';
import { OpenAiEmbeddings } from '@llm-tools/embedjs-openai';
import { HNSWDb } from '@llm-tools/embedjs-hnswlib';
import { TwelveLabsVideoLoader } from '@llm-tools/embedjs-twelvelabs';
const app = await new RAGApplicationBuilder()
.setModel(SIMPLE_MODELS.OPENAI_GPT4_O)
.setEmbeddingModel(new OpenAiEmbeddings())
.setVectorDatabase(new HNSWDb())
.build();
app.addLoader(new TwelveLabsVideoLoader({ url: 'https://example.com/video.mp4' }))
```
You can customise the analysis with an optional `prompt`, `model` (`pegasus1.2` or `pegasus1.5`) and `maxTokens`:
```ts theme={null}
app.addLoader(new TwelveLabsVideoLoader({
url: 'https://example.com/video.mp4',
prompt: 'Summarize the key moments in this video.',
model: 'pegasus1.2',
maxTokens: 2048,
}))
```
# π HTML Web page
Source: https://llm-tools.mintlify.app/components/data-sources/web-page
To add any web page, use the data\_type as `WebLoader`.
## Install Web addon
```bash theme={null}
npm install @llm-tools/embedjs-loader-web
```
## Usage
```ts theme={null}
import { RAGApplicationBuilder } from '@llm-tools/embedjs';
import { OpenAiEmbeddings } from '@llm-tools/embedjs-openai';
import { HNSWDb } from '@llm-tools/embedjs-hnswlib';
import { WebLoader } from '@llm-tools/embedjs-loader-web';
const app = await new RAGApplicationBuilder()
.setModel(SIMPLE_MODELS.OPENAI_GPT4_O)
.setEmbeddingModel(new OpenAiEmbeddings())
.setVectorDatabase(new HNSWDb())
.build();
app.addLoader(new WebLoader({ urlOrContent: '...' }))
```
# π§Ύ XML
Source: https://llm-tools.mintlify.app/components/data-sources/xml
You can load any XML file from your local file system or through a URL.
Headers are included for each line, so if you have an `age` column, `18` will be added as `age: 18`.
## Install XML addon
```bash theme={null}
npm install @llm-tools/embedjs-loader-xml
```
## Usage
### Load from a local file
```ts theme={null}
import { RAGApplicationBuilder } from '@llm-tools/embedjs';
import { OpenAiEmbeddings } from '@llm-tools/embedjs-openai';
import { HNSWDb } from '@llm-tools/embedjs-hnswlib';
import { XmlLoader } from '@llm-tools/embedjs-loader-csv';
const app = await new RAGApplicationBuilder()
.setModel(SIMPLE_MODELS.OPENAI_GPT4_O)
.setEmbeddingModel(new OpenAiEmbeddings())
.setVectorDatabase(new HNSWDb())
.build();
app.addLoader(new XmlLoader({ filePathOrUrl: '/path/to/file.xml' }))
```
### Load from URL
```ts theme={null}
import { RAGApplicationBuilder } from '@llm-tools/embedjs';
import { OpenAiEmbeddings } from '@llm-tools/embedjs-openai';
import { HNSWDb } from '@llm-tools/embedjs-hnswlib';
import { XmlLoader } from '@llm-tools/embedjs-loader-csv';
const app = await new RAGApplicationBuilder()
.setModel(SIMPLE_MODELS.OPENAI_GPT4_O)
.setEmbeddingModel(new OpenAiEmbeddings())
.setVectorDatabase(new HNSWDb())
.build();
app.addLoader(new XmlLoader({ filePathOrUrl: 'https://www.w3schools.com/xml/plant_catalog.xml' }))
```
# π½οΈ Youtube Channel
Source: https://llm-tools.mintlify.app/components/data-sources/youtube-channel
To add all the videos from a youtube channel to your app, use the `YoutubeChannelLoader`.
## Install Youtube addon
```bash theme={null}
npm install @llm-tools/embedjs-loader-youtube
```
## Usage
```ts theme={null}
import { RAGApplicationBuilder } from '@llm-tools/embedjs';
import { OpenAiEmbeddings } from '@llm-tools/embedjs-openai';
import { HNSWDb } from '@llm-tools/embedjs-hnswlib';
import { YoutubeChannelLoader } from '@llm-tools/embedjs-loader-youtube';
const app = await new RAGApplicationBuilder()
.setModel(SIMPLE_MODELS.OPENAI_GPT4_O)
.setEmbeddingModel(new OpenAiEmbeddings())
.setVectorDatabase(new HNSWDb())
.build();
app.addLoader(new YoutubeChannelLoader({ youtubeChannelId: '...' }))
```
# π Youtube Search
Source: https://llm-tools.mintlify.app/components/data-sources/youtube-search
To automatically perform a youtube search and load the top youtube videos to your app, use the `YoutubeSearchLoader`.
## Install Youtube addon
```bash theme={null}
npm install @llm-tools/embedjs-loader-youtube
```
## Usage
```ts theme={null}
import { RAGApplicationBuilder } from '@llm-tools/embedjs';
import { OpenAiEmbeddings } from '@llm-tools/embedjs-openai';
import { HNSWDb } from '@llm-tools/embedjs-hnswlib';
import { YoutubeSearchLoader } from '@llm-tools/embedjs-loader-youtube';
const app = await new RAGApplicationBuilder()
.setModel(SIMPLE_MODELS.OPENAI_GPT4_O)
.setEmbeddingModel(new OpenAiEmbeddings())
.setVectorDatabase(new HNSWDb())
.build();
app.addLoader(new YoutubeSearchLoader({ youtubeSearchString: '...' }))
```
# πΊ Youtube Video
Source: https://llm-tools.mintlify.app/components/data-sources/youtube-video
To add any youtube video to your app, use the `YoutubeLoader`.
## Install Youtube addon
```bash theme={null}
npm install @llm-tools/embedjs-loader-youtube
```
## Usage
```ts theme={null}
import { RAGApplicationBuilder } from '@llm-tools/embedjs';
import { OpenAiEmbeddings } from '@llm-tools/embedjs-openai';
import { HNSWDb } from '@llm-tools/embedjs-hnswlib';
import { YoutubeLoader } from '@llm-tools/embedjs-loader-youtube';
const app = await new RAGApplicationBuilder()
.setModel(SIMPLE_MODELS.OPENAI_GPT4_O)
.setEmbeddingModel(new OpenAiEmbeddings())
.setVectorDatabase(new HNSWDb())
.build();
app.addLoader(new YoutubeLoader({ videoIdOrUrl: '...' }))
```
# Azure OpenAI
Source: https://llm-tools.mintlify.app/components/embeddings/azure-openai
In order to be able to use OpenAI models on Azure, they first need to be deployed.
Please refer to [Azure OpenAI documentation](https://learn.microsoft.com/en-us/azure/cognitive-services/openai/) on how to deploy a model on Azure.
Once these models are deployed, using Azure OpenAI is easy to do. Just follow these steps -
* Set the following environment variables -
```bash theme={null}
AZURE_OPENAI_API_INSTANCE_NAME=
AZURE_OPENAI_API_EMBEDDINGS_DEPLOYMENT_NAME=
AZURE_OPENAI_API_VERSION="2024-02-01" #or a newer version
AZURE_OPENAI_API_KEY=
```
## Install OpenAI addon
```bash theme={null}
npm install @llm-tools/embedjs-openai
```
## Usage
```ts theme={null}
import { RAGApplicationBuilder } from '@llm-tools/embedjs';
import { AzureOpenAiEmbeddings } from '@llm-tools/embedjs-openai';
import { HNSWDb } from '@llm-tools/embedjs-hnswlib';
const app = await new RAGApplicationBuilder()
.setEmbeddingModel(new AzureOpenAiEmbeddings({
model: 'text-embedding-3-large'
}))
```
The following embedding models do not require you to pass a dimension parameter -
* `text-embedding-3-large`
* `text-embedding-3-small`
* `text-embedding-ada-002`
All other models require you provide one.
To use Azure Managed Identity, you can use something similar to the following code snippet -
```ts theme={null}
import {
DefaultAzureCredential,
getBearerTokenProvider,
} from "@azure/identity";
import { AzureOpenAiEmbeddings } from '@llm-tools/embedjs-openai';
const credentials = new DefaultAzureCredential();
const azureADTokenProvider = getBearerTokenProvider(
credentials,
"https://cognitiveservices.azure.com/.default"
);
const app = await new RAGApplicationBuilder()
.setEmbeddingModel(new AzureOpenAiEmbeddings({
azureADTokenProvider,
azureOpenAIApiInstanceName: "",
azureOpenAIApiEmbeddingsDeploymentName: "",
azureOpenAIApiVersion: "",
}))
```
# Cohere
Source: https://llm-tools.mintlify.app/components/embeddings/cohere
The library supports usage of [Cohere-AI](https://cohere.com) `embed-english-v2.0` embedding model out of the box. This model returns vectors with dimension 4096.
Here's what you have to do to use it -
* Sign up for an account with Cohere-AI, go to the [API Keys](https://dashboard.cohere.ai/api-keys) section and copy / create an API\_KEY.
* Set the key in the environment variable `COHERE_API_KEY`
```bash theme={null}
COHERE_API_KEY=""
```
## Install Cohere addon
```bash theme={null}
npm install @llm-tools/embedjs-cohere
```
## Usage
```ts theme={null}
import { RAGApplicationBuilder } from '@llm-tools/embedjs';
import { CohereEmbeddings } from '@llm-tools/embedjs-cohere';
import { HNSWDb } from '@llm-tools/embedjs-hnswlib';
const app = await new RAGApplicationBuilder()
.setEmbeddingModel(new CohereEmbeddings())
```
# Hugging Face
Source: https://llm-tools.mintlify.app/components/embeddings/huggingface
The library supports generating embeddings using the Hugging Face Inference API.
By default it uses the `sentence-transformers/distilbert-base-nli-mean-tokens` model but you can pass it a model parameter to use any other model available on the Hugging Face model hub.
To use Hugging face embedding models via its Inference API, you need to get a free token.
You can get this API Token by signing up for hugging face and visiting [this page](https://huggingface.co/settings/tokens).
Set it to the environment like so -
```bash theme={null}
HUGGINGFACEHUB_API_KEY=""
```
## Install Huggingface addon
```bash theme={null}
npm install @llm-tools/embedjs-huggingface
```
## Usage
```ts theme={null}
import { RAGApplicationBuilder } from '@llm-tools/embedjs';
import { HuggingFaceEmbeddings } from '@llm-tools/embedjs-huggingface';
import { HNSWDb } from '@llm-tools/embedjs-hnswlib';
const app = await new RAGApplicationBuilder()
.setEmbeddingModel(new HuggingFaceEmbeddings())
```
# Ollama
Source: https://llm-tools.mintlify.app/components/embeddings/ollama
EmbedJs supports local embeddings via `Ollama`. Read more here [Ollama embeddings](https://ollama.com/blog/embedding-models).
To use this, you need to setup and have Ollama working locally. Refer to their Github [here](https://github.com/ollama/ollama) to understand how to do this.
Once done, follow these steps -
## Install Ollama addon
```bash theme={null}
npm install @llm-tools/embedjs-ollama
```
## Usage
```ts theme={null}
import { RAGApplicationBuilder } from '@llm-tools/embedjs';
import { OllamaEmbeddings } from '@llm-tools/embedjs-ollama';
const app = await new RAGApplicationBuilder()
.setEmbeddingModel(new OllamaEmbeddings({
modelName: "...",
baseUrl: 'http://localhost:11434'
}))
```
# OpenAI
Source: https://llm-tools.mintlify.app/components/embeddings/openai
To use the OpenAI embedding models, you need a API key from OpenAI.
You can alternatively use Azure OpenAI to run most of the OpenAI embedding models. Read the [Azure OpenAI](/components/llms/azure-openai) section to learn more about this.
To get started, obtain an API Key from OpenAI. You can do this by visiting their [API Portal](https://platform.openai.com/api-keys).
Once you obtain a key, set it in an environment variable, like so -
```bash theme={null}
OPENAI_API_KEY=""
```
## Install OpenAI addon
```bash theme={null}
npm install @llm-tools/embedjs-openai
```
## Usage
```ts theme={null}
import { RAGApplicationBuilder } from '@llm-tools/embedjs';
import { OpenAiEmbeddings } from '@llm-tools/embedjs-openai';
import { HNSWDb } from '@llm-tools/embedjs-hnswlib';
const app = await new RAGApplicationBuilder()
.setEmbeddingModel(new OpenAiEmbeddings({
model: 'text-embedding-3-large'
}))
```
The following embedding models do not require you to pass a dimension parameter -
* `text-embedding-3-large`
* `text-embedding-3-small`
* `text-embedding-ada-002`
All other models require you provide one.
# Overview
Source: https://llm-tools.mintlify.app/components/embeddings/overview
EmbedJs supports several embedding models from the following providers:
# TwelveLabs (Marengo)
Source: https://llm-tools.mintlify.app/components/embeddings/twelvelabs
The library supports usage of the [TwelveLabs](https://twelvelabs.io) `marengo3.0` multimodal embedding model out of the box. Marengo embeds text, image, audio and video into a single shared latent space, which makes it a great fit for retrieval over video libraries. This model returns vectors with dimension 512.
Here's what you have to do to use it -
* Sign up for an account with TwelveLabs and grab an API key. There's a generous free tier at [twelvelabs.io](https://twelvelabs.io).
* Set the key in the environment variable `TWELVELABS_API_KEY` (or pass it directly to the constructor).
```bash theme={null}
TWELVELABS_API_KEY=""
```
## Install TwelveLabs addon
```bash theme={null}
npm install @llm-tools/embedjs-twelvelabs
```
## Usage
```ts theme={null}
import { RAGApplicationBuilder } from '@llm-tools/embedjs';
import { MarengoEmbeddings } from '@llm-tools/embedjs-twelvelabs';
import { HNSWDb } from '@llm-tools/embedjs-hnswlib';
const app = await new RAGApplicationBuilder()
.setEmbeddingModel(new MarengoEmbeddings())
```
You can also pass the API key explicitly:
```ts theme={null}
new MarengoEmbeddings({ apiKey: 'YOUR_KEY' })
```
# Vertex AI
Source: https://llm-tools.mintlify.app/components/embeddings/vertexai
The libaray supports the Gecko Embedding model on [VertexAI](https://cloud.google.com/vertex-ai/generative-ai/docs/embeddings/get-text-embeddings) with 768 dimensions.
To use this model, you need to authenticate to Vertex AI on GCP. Refer [here](/components/llms/azure-openai) on how to do this. Once done, follow these steps -
## Install VertexAi addon
```bash theme={null}
npm install @llm-tools/embedjs-vertexai
```
## Usage
```ts theme={null}
import { RAGApplicationBuilder } from '@llm-tools/embedjs';
import { GeckoEmbeddings } from '@llm-tools/embedjs-vertexai';
import { HNSWDb } from '@llm-tools/embedjs-hnswlib';
const app = await new RAGApplicationBuilder()
.setEmbeddingModel(new GeckoEmbeddings())
```
# EmbedJs Components
Source: https://llm-tools.mintlify.app/components/introduction
## Overview
You can configure following components in an EmbedJs application -
* [LLM](/components/llms)
* [Embedding Model](/components/embeddings)
* [Data Source](/components/data-sources)
* [Vector Database](/components/vector-databases)
* [Stores](/components/stores)
# Anthropic
Source: https://llm-tools.mintlify.app/components/llms/anthropic
To use Anthropic's Claude models, you will need to get an API Key from Anthropic.
You can do this from their [console](https://console.anthropic.com/settings/keys). Once you obtain a key, set it in the environment variable, like so -
```bash theme={null}
ANTHROPIC_API_KEY=""
```
## Install Anthtopic addon
```bash theme={null}
npm install @llm-tools/embedjs-anthropic
```
## Usage
```ts theme={null}
import { RAGApplicationBuilder } from '@llm-tools/embedjs';
import { Anthropic } from '@llm-tools/embedjs-anthropic';
const app = await new RAGApplicationBuilder()
.setModel(new Anthropic({ modelName: "..." }))
```
# Azure OpenAI
Source: https://llm-tools.mintlify.app/components/llms/azure-openai
In order to be able to use OpenAI models on Azure, they first need to be deployed.
Please refer to [Azure OpenAI documentation](https://learn.microsoft.com/en-us/azure/cognitive-services/openai/) on how to deploy a model on Azure.
Once these models are deployed, using Azure OpenAI is easy to do. Just follow these steps -
* Set the following environment variables -
```bash theme={null}
AZURE_OPENAI_API_INSTANCE_NAME=
AZURE_OPENAI_API_DEPLOYMENT_NAME=
AZURE_OPENAI_API_VERSION="2024-02-01" #or a newer version
AZURE_OPENAI_API_KEY=
```
## Install OpenAI addon
```bash theme={null}
npm install @llm-tools/embedjs-openai
```
## Usage
```ts theme={null}
import { RAGApplicationBuilder } from '@llm-tools/embedjs';
import { AzureOpenAi } from '@llm-tools/embedjs-openai';
const app = await new RAGApplicationBuilder()
.setModel(new AzureOpenAi({ model: "gpt-4o" }))
```
To use Azure Managed Identity, you can use something similar to the following code snippet -
```ts theme={null}
import {
DefaultAzureCredential,
getBearerTokenProvider,
} from "@azure/identity";
import { AzureOpenAi } from '@llm-tools/embedjs-openai';
const credentials = new DefaultAzureCredential();
const azureADTokenProvider = getBearerTokenProvider(
credentials,
"https://cognitiveservices.azure.com/.default"
);
const app = new AzureOpenAI({
azureADTokenProvider,
azureOpenAIApiInstanceName: "",
azureOpenAIApiDeploymentName: "",
azureOpenAIApiVersion: "",
});
```
# Hugging Face
Source: https://llm-tools.mintlify.app/components/llms/huggingface
Hugging face needs no introduction. They host a variety of open source LLMs and you can use most of them for free. To run hugging face inference based LLMs with this library, you will need a free hugging face token.
You can get an API Token by signing up for hugging face and generate a token from [this page](https://huggingface.co/settings/tokens). Once you get the token, set it to the environment like so -
```bash theme={null}
HUGGINGFACEHUB_API_KEY=""
```
## Install Huggingface addon
```bash theme={null}
npm install @llm-tools/embedjs-huggingface
```
## Usage
```ts theme={null}
import { RAGApplicationBuilder } from '@llm-tools/embedjs';
import { HuggingFace } from '@llm-tools/embedjs-huggingface';
const app = await new RAGApplicationBuilder()
.setModel(new HuggingFace({ modelName: "..." }))
```
# Mistral
Source: https://llm-tools.mintlify.app/components/llms/mistral
To use Mirstal's models, you will need to get an API Key from Mistral. You can do this from their [console](https://console.mistral.ai/user/api-keys/).
## Install Mistral addon
```bash theme={null}
npm install @llm-tools/embedjs-mistral
```
## Usage
```ts theme={null}
import { RAGApplicationBuilder } from '@llm-tools/embedjs';
import { Anthropic } from '@llm-tools/embedjs-mistral';
const app = await new RAGApplicationBuilder()
.setModel(new Mistral({ accessToken: "", modelName: "..." }))
```
# Ollama
Source: https://llm-tools.mintlify.app/components/llms/ollama
You can also use locally running Ollama models. Installation instructions for Ollama can be found [here](https://ollama.com/).
Once Ollama is installed, you can start a local LLM by executing `ollama run `.
## Install Ollama addon
```bash theme={null}
npm install @llm-tools/embedjs-ollama
```
## Usage
```ts theme={null}
import { RAGApplicationBuilder } from '@llm-tools/embedjs';
import { Ollama } from '@llm-tools/embedjs-ollama';
const app = await new RAGApplicationBuilder()
.setModel(new Ollama({
modelName: "llama3",
baseUrl: 'http://localhost:11434'
}))
```
# OpenAI
Source: https://llm-tools.mintlify.app/components/llms/openai
To use the OpenAI LLM models, you need a API key from OpenAI.
You can alternatively use Azure OpenAI to run most of the OpenAI LLMs. Read the [Azure OpenAI](/components/llms/azure-openai) section to learn more about this.
To get started, obtain an API Key from OpenAI. You can do this by visiting their [API Portal](https://platform.openai.com/api-keys).
Once you obtain a key, set it in an environment variable, like so -
```bash theme={null}
OPENAI_API_KEY=""
```
## Install OpenAI addon
```bash theme={null}
npm install @llm-tools/embedjs-openai
```
## Usage
```ts theme={null}
import { RAGApplicationBuilder } from '@llm-tools/embedjs';
import { OpenAi } from '@llm-tools/embedjs-openai';
const app = await new RAGApplicationBuilder()
.setModel(new OpenAi({ model: "text-davinci-003" }))
```
# Overview
Source: https://llm-tools.mintlify.app/components/llms/overview
EmbedJs comes with built-in support for various popular large language models. We handle the complexity of integrating these models for you, allowing you to easily customize your language model interactions through a user-friendly interface.
## Token Usage
The list of LLMs that support token usage are:
* OpenAI
* Vertex AI
* Anthropic
* Mistral AI
# Vertex AI
Source: https://llm-tools.mintlify.app/components/llms/vertexai
You to use Gemini LLM and other models on Google Cloud Platform via [VertexAI](https://cloud.google.com/vertex-ai?hl=en).
Read more about all the supported [LLMs](https://cloud.google.com/vertex-ai/generative-ai/docs/learn/models).
To get started, you need to set the right access credentials to google cloud. You have two options here -
* Authenticate by using `gcloud` CLI:
```
gcloud auth application-default login
```
* Authentication using Service Account with JSON key and environment variable:
```bash theme={null}
GOOGLE_APPLICATION_CREDENTIALS=""
```
Once this is done, you can configure your embedJs app -
## Install VertexAi addon
```bash theme={null}
npm install @llm-tools/embedjs-vertexai
```
## Usage
```ts theme={null}
import { RAGApplicationBuilder } from '@llm-tools/embedjs';
import { Ollama } from '@llm-tools/embedjs-vertexai';
const app = await new RAGApplicationBuilder()
.setModel(new VertexAI({ modelName: 'gemini-1.5-pro-preview-0409'}))
```
# LibSQL
Source: https://llm-tools.mintlify.app/components/stores/libsql
You can use [LibSQL](https://docs.turso.tech/introduction) a fork of SQLite to store values locally on disk.
## Install LibSQL addon
```bash theme={null}
npm install @llm-tools/embedjs-libsql
```
## Usage
```ts Partial example theme={null}
import { RAGApplicationBuilder } from '@llm-tools/embedjs';
import { LibSqlStore } from '@llm-tools/embedjs-libsql';
const app = await new RAGApplicationBuilder()
.setStore(new LibSqlStore({ path: './data.db' }))
```
# LMDB
Source: https://llm-tools.mintlify.app/components/stores/lmdb
You can use [LMDB](https://dbdb.io/db/lmdb) to store values locally on disk.
## Install LMDB addon
```bash theme={null}
npm install @llm-tools/embedjs-lmdb
```
## Usage
```ts Partial example theme={null}
import { RAGApplicationBuilder } from '@llm-tools/embedjs';
import { LmdbStore } from '@llm-tools/embedjs-lmdb';
const app = await new RAGApplicationBuilder()
.setStore(new LmdbStore({ path: path.resolve('./store') }))
```
# MongoDB
Source: https://llm-tools.mintlify.app/components/stores/mongodb
You can use MongoDB as a data store. This creates three new collections in the database - which are configureable.
MongoDB is also supported as a vector database. This is separate from that.
## Install MongoDB addon
```bash theme={null}
npm install @llm-tools/embedjs-mongodb
```
## Usage
```ts Partial example theme={null}
import { RAGApplicationBuilder } from '@llm-tools/embedjs';
import { MongoStore } from '@llm-tools/embedjs-mongodb';
const app = await new RAGApplicationBuilder()
.setStore(new MongoStore({ ... }))
```
# Overview
Source: https://llm-tools.mintlify.app/components/stores/overview
EmbedJs comes with built-in support for data persistance beyond vector embeddings. The kind of data that can be persisted includes -
* Loaders and chunks loaded and their metadata
* Loader specific caching
* Conversation history
The library handles the complexity of being able to swap the data persistance layer by the abstraction of stores. The following stores have built-in support -
# Redis
Source: https://llm-tools.mintlify.app/components/stores/redis
You can use redis as a data store.
## Install Redis addon
```bash theme={null}
npm install @llm-tools/embedjs-redis
```
## Usage
```ts Partial example theme={null}
import { RAGApplicationBuilder } from '@llm-tools/embedjs';
import { RedisStore } from '@llm-tools/embedjs-redis';
const app = await new RAGApplicationBuilder()
.setStore(new RedisStore({ ... }))
```
# AstraDB
Source: https://llm-tools.mintlify.app/components/vector-databases/astradb
[AstraDB](https://www.datastax.com/products/datastax-astra) is a document database with a highly performant vector index powered by Apache Cassandra and available as a managed service.
To use Astra as database -
* [Sign up](https://astra.datastax.com/signup) for an AstraDB account. It is free to sign up and doesn't require a credit card.
* Create a database (this takes a couple of minutes to provision)
* From the database overview page get the API Endpoint and generate an Application Token
## Install AstraDB addon
```bash theme={null}
npm install @llm-tools/embedjs-astradb
```
## Usage
```ts Example theme={null}
import { RAGApplicationBuilder } from '@llm-tools/embedjs';
import { OpenAiEmbeddings } from '@llm-tools/embedjs-openai';
import { AstraDb } from '@llm-tools/embedjs-astradb';
import { WebLoader } from '@llm-tools/embedjs-loader-web';
// set OPENAI_API_KEY in your env
process.env.OPENAI_API_KEY = "sk-xxx";
const app = await new RAGApplicationBuilder()
.setEmbeddingModel(new OpenAiEmbeddings())
.setModel(SIMPLE_MODELS.OPENAI_GPT4_O)
.setVectorDatabase(
new AstraDb({
endpoint: "",
apiKey: "",
collectionName: "documents"
})
)
.build();
//add data source and start query it
await app.addLoader(new WebLoader({ urlOrContent: 'https://www.forbes.com/profile/elon-musk' }));
await app.query('Tell me about Elon Musk');
```
# HNSWLib
Source: https://llm-tools.mintlify.app/components/vector-databases/hnswlib
[HNSWLib](https://github.com/nmslib/hnswlib) is an high performance in-memory vectorstore.
It is great for testing since you do not need access to the file system or a cloud service.
## Install HNSWLib addon
```bash theme={null}
npm install @llm-tools/embedjs-hnswlib
```
## Usage
```ts Example theme={null}
import { RAGApplicationBuilder } from '@llm-tools/embedjs';
import { OpenAiEmbeddings } from '@llm-tools/embedjs-openai';
import { HNSWDb } from '@llm-tools/embedjs-hnswlib';
import { WebLoader } from '@llm-tools/embedjs-loader-web';
// set OPENAI_API_KEY in your env
process.env.OPENAI_API_KEY = "sk-xxx";
const app = await new RAGApplicationBuilder()
.setEmbeddingModel(new OpenAiEmbeddings())
.setModel(SIMPLE_MODELS.OPENAI_GPT4_O)
.setVectorDatabase(new HNSWDb())
.build();
//add data source and start query it
await app.addLoader(new WebLoader({ urlOrContent: 'https://www.forbes.com/profile/elon-musk' }));
await app.query('Tell me about Elon Musk');
```
# LanceDB
Source: https://llm-tools.mintlify.app/components/vector-databases/lancedb
LanceDB is a developer-friendly, open source database with great performance.
From hyper scalable vector search and advanced retrieval for RAG, to streaming training data and interactive exploration of large scale AI datasets.
You can run LanceDB locally and it is integrated into the LanceDb addon for EmbedJs.
## Install LanceDB addon
```bash theme={null}
npm install @llm-tools/embedjs-lancedb
```
## Usage
```ts Example theme={null}
import { RAGApplicationBuilder } from '@llm-tools/embedjs';
import { OpenAiEmbeddings } from '@llm-tools/embedjs-openai';
import { LanceDb } from '@llm-tools/embedjs-lancedb';
import { WebLoader } from '@llm-tools/embedjs-loader-web';
// set OPENAI_API_KEY in your env
process.env.OPENAI_API_KEY = "sk-xxx";
const app = await new RAGApplicationBuilder()
.setEmbeddingModel(new OpenAiEmbeddings())
.setModel(SIMPLE_MODELS.OPENAI_GPT4_O)
.setVectorDatabase(
new LanceDb({
path: './lmdb',
}),
)
.build();
//add data source and start query it
await app.addLoader(new WebLoader({ urlOrContent: 'https://www.forbes.com/profile/elon-musk' }));
await app.query('Tell me about Elon Musk');
```
# LibSQL
Source: https://llm-tools.mintlify.app/components/vector-databases/libsql
LibSQL is an open source fork of SQLite and in most cases it is a drop in replacement for SQLite. It has native in-built support for vector similarity search.
Read more about LibSQL's support for AI [here](https://docs.turso.tech/features/ai-and-embeddings).
You can run LibSQL locally with EmbedJs and is available via the LibSQL extension for embedJs.
LibSql can also be used to store conversations and other data generated in embedJs.
This is done via the LibSqlStore available in the LibSQL extension for embedJs. Read more about it [here](/components/stores/libsql)
## Install LibSQL addon
```bash theme={null}
npm install @llm-tools/embedjs-libsql
```
## Usage
```ts Example theme={null}
import { RAGApplicationBuilder } from '@llm-tools/embedjs';
import { OpenAiEmbeddings } from '@llm-tools/embedjs-openai';
import { WebLoader } from '@llm-tools/embedjs-loader-web';
import { LibSqlDb } from '@llm-tools/embedjs-libsql';
// set OPENAI_API_KEY in your env
process.env.OPENAI_API_KEY = "sk-xxx";
const app = await new RAGApplicationBuilder()
.setVectorDatabase(new LibSqlDb({ path: './data.db' }))
.setEmbeddingModel(new OpenAiEmbeddings())
.setModel(SIMPLE_MODELS.OPENAI_GPT4_O)
.build();
//add data source and start query it
await app.addLoader(new WebLoader({ urlOrContent: 'https://www.forbes.com/profile/elon-musk' }));
await app.query('Tell me about Elon Musk');
```
# MongoDB
Source: https://llm-tools.mintlify.app/components/vector-databases/mongodb
[MongoDB](https://www.mongodb.com/products/platform/atlas-vector-search) is an open source document database.
The company behind the open source product offers a managed cloud product **MongoDB Atlas**.
As of right now, only the Atlas version supports vector search while the open source version does not.
To use MongoDB as your vector database, follow these steps -
* Sign up for a MongoDB Atlas account if you haven't already. Once you have signed up, you will need to spin up a new cluster (or use an existing one)
You will need to provision a M10 (or higher) instance type to use Atlas vector search. Cheaper instance types or the free version (M0) give an error when vector indexes are created programatically.
* The cluster creation takes a few minutes. Once the cluster is ready, click on the connect button on the dashboard to get the connection string.
You will need to add users separately and allow IP access from your relevant development and production environments.
## Install MongoDB addon
```bash theme={null}
npm install @llm-tools/embedjs-mongodb
```
## Usage
```ts Example theme={null}
import { RAGApplicationBuilder } from '@llm-tools/embedjs';
import { OpenAiEmbeddings } from '@llm-tools/embedjs-openai';
import { MongoDb } from '@llm-tools/embedjs-mongodb';
import { WebLoader } from '@llm-tools/embedjs-loader-web';
// set OPENAI_API_KEY in your env
process.env.OPENAI_API_KEY = "sk-xxx";
const app = await new RAGApplicationBuilder()
.setEmbeddingModel(new OpenAiEmbeddings())
.setModel(SIMPLE_MODELS.OPENAI_GPT4_O)
.setVectorDatabase(new MongoDb({
connectionString: 'mongodb+srv://:@',
})),
.build();
//add data source and start query it
await app.addLoader(new WebLoader({ urlOrContent: 'https://www.forbes.com/profile/elon-musk' }));
await app.query('Tell me about Elon Musk');
```
# Overview
Source: https://llm-tools.mintlify.app/components/vector-databases/overview
## Overview
Utilizing a vector database alongside EmbedJs is a seamless process.
All you need to do is install the specific addon for the vector database of your choice and configure it.
We've provided examples for each supported database below:
# Pinecone
Source: https://llm-tools.mintlify.app/components/vector-databases/pinecone
To get started, create an account with [Pinecone](https://www.pinecone.io/) if you don't have one already. There is a free tier.
Once you have an account, get an API key from the **API Keys** section on the Pinecone dashboard.
Add the API Key to your environment variables.
```bash theme={null}
PINECONE_API_KEY=
```
## Install Pinecone addon
```bash theme={null}
npm install @llm-tools/embedjs-pinecone
```
## Usage
```ts Example theme={null}
import { RAGApplicationBuilder } from '@llm-tools/embedjs';
import { OpenAiEmbeddings } from '@llm-tools/embedjs-openai';
import { PineconeDb } from '@llm-tools/embedjs-pinecone';
import { WebLoader } from '@llm-tools/embedjs-loader-web';
// set OPENAI_API_KEY in your env
process.env.OPENAI_API_KEY = "sk-xxx";
const app = await new RAGApplicationBuilder()
.setEmbeddingModel(new OpenAiEmbeddings())
.setModel(SIMPLE_MODELS.OPENAI_GPT4_O)
.setVectorDatabase(new PineconeDb({
projectName: '',
namespace: '',
indexSpec: {
pod: {
podType: 'p1.x1',
environment: 'us-east1-gcp',
},
},
}))
.build();
//add data source and start query it
await app.addLoader(new WebLoader({ urlOrContent: 'https://www.forbes.com/profile/elon-musk' }));
await app.query('Tell me about Elon Musk');
```
# Qdrant
Source: https://llm-tools.mintlify.app/components/vector-databases/qdrant
[Qdrant](https://qdrant.tech/) is a Vector Search Engine written in Rust. You will need to sign up to get an API key and URL to use Qdrant.
## Install Qdrant addon
```bash theme={null}
npm install @llm-tools/embedjs-pinecone
```
## Usage
```ts Example theme={null}
import { RAGApplicationBuilder } from '@llm-tools/embedjs';
import { OpenAiEmbeddings } from '@llm-tools/embedjs-openai';
import { QdrantDb } from '@llm-tools/embedjs-qdrant';
import { WebLoader } from '@llm-tools/embedjs-loader-web';
// set OPENAI_API_KEY in your env
process.env.OPENAI_API_KEY = "sk-xxx";
const app = await new RAGApplicationBuilder()
.setEmbeddingModel(new OpenAiEmbeddings())
.setModel(SIMPLE_MODELS.OPENAI_GPT4_O)
.setVectorDatabase(new QdrantDb({ apiKey: '...'; url: '...'; clusterName: '...' }))
.build();
//add data source and start query it
await app.addLoader(new WebLoader({ urlOrContent: 'https://www.forbes.com/profile/elon-musk' }));
await app.query('Tell me about Elon Musk');
```
# Weaviate
Source: https://llm-tools.mintlify.app/components/vector-databases/weaviate
[Weaviate](https://weaviate.io/) is an open source vector store. You can deploy it locally on docker or use their managed cloud offering.
## Install Qdrant addon
```bash theme={null}
npm install @llm-tools/embedjs-weaviate
```
## Usage
```ts Example theme={null}
import { RAGApplicationBuilder } from '@llm-tools/embedjs';
import { OpenAiEmbeddings } from '@llm-tools/embedjs-openai';
import { WeaviateDb } from '@llm-tools/embedjs-weaviate';
import { WebLoader } from '@llm-tools/embedjs-loader-web';
// set OPENAI_API_KEY in your env
process.env.OPENAI_API_KEY = "sk-xxx";
const app = await new RAGApplicationBuilder()
.setModel(SIMPLE_MODELS.OPENAI_GPT4_O)
.setEmbeddingModel(new OpenAiEmbeddings())
.setVectorDatabase(new WeaviateDb({ host: '...', apiKey: '...', className: '...', scheme: '...' }))
.build();
//add data source and start query it
await app.addLoader(new WebLoader({ urlOrContent: 'https://www.forbes.com/profile/elon-musk' }));
await app.query('Tell me about Elon Musk');
```
# π¨βπ» Development
Source: https://llm-tools.mintlify.app/contribution/dev
Contribute to EmbedJs framework development
Thank you for your interest in contributing to the EmbedJs project! We welcome your ideas and contributions to help improve the project. Please follow the instructions below to get started:
1. **Fork the repository**: Click on the "Fork" button at the top right corner of this repository page. This will create a copy of the repository in your own GitHub account.
2. **Install the required dependencies**: Ensure that you have the necessary dependencies installed. You can do this by running the following command:
```bash theme={null}
npm install
```
3. **Make changes in the code**: Create a new branch in your forked repository and make your desired changes in the codebase.
4. **Create a pull request**: When you are ready to contribute your changes, submit a pull request to the EmbedJs repository. Provide a clear and descriptive title for your pull request, along with a detailed description of the changes you have made.
## Team
### Maintainers
* Adhityan K V ([@kvadhityan](https://twitter.com/kvadhityan))
### Citation
If you utilize this repository, please consider citing it with:
```
@misc{embedJs,
author = {Adhityan K V},
title = {EmbedJs: The Open Source RAG Framework},
year = {2023},
publisher = {GitHub},
journal = {GitHub repository},
howpublished = {\url{https://github.com/llm-tools/embedjs}},
}
```
# π Documentation
Source: https://llm-tools.mintlify.app/contribution/docs
Contribute to EmbedJs docs
Thank you for your interest in contributing to the EmbedJs project documentation! Please follow the instructions below to get started:
Step 1. Go to the `docs/` directory (where you can find `mint.json`) and run the following command:
```bash theme={null}
npx mintlify dev
```
The documentation website is now available at `http://localhost:3000`.
### Custom Ports
Mintlify uses port 3000 by default. You can use the `--port` flag to customize the port Mintlify runs on. For example, use this command to run in port 3333:
```bash theme={null}
mintlify dev --port 3333
```
You will see an error like this if you try to run Mintlify in a port that's already taken:
```md theme={null}
Error: listen EADDRINUSE: address already in use :::3000
```
# π Guidelines
Source: https://llm-tools.mintlify.app/contribution/guidelines
# πΌ Slack Bot
Source: https://llm-tools.mintlify.app/examples/slack_bot
### πΌοΈ Setup
1. Create a workspace on Slack if you don't have one already by clicking [here](https://slack.com/intl/en-in/).
2. Create a new App on your Slack account by going [here](https://api.slack.com/apps).
3. Select `From Scratch`, then enter the Bot Name and select your workspace.
4. On the left Sidebar, go to `OAuth and Permissions` and add the following scopes under `Bot Token Scopes`:
```text theme={null}
app_mentions:read
channels:read
chat:write
```
5. Now select the option `Install to Workspace` and after it's done, copy the `Bot User OAuth Token` and set it in your secrets as `SLACK_BOT_TOKEN`.
6. Clone the example slack repo from [here](https://github.com/llm-tools/slack-bot-template).
7. Run NPM install and start the server. The application starts and prints by default a `NGROK reverse proxy URL` to the console.
8. On the Slack API website go to `Event Subscriptions` on the left Sidebar and turn on `Enable Events`.
9. In `Request URL`, enter your server or ngrok address.
10. After it gets verified, click on `Subscribe to bot events`, add `message.channels` Bot User Event and click on `Save Changes`.
11. Now go to your workspace, right click on the bot name in the sidebar, click `view app details`, then `add this app to a channel`.
### π Usage Instructions
* Go to the channel where you have added your bot.
* To add data sources to the bot, use the command:
```text theme={null}
/learnfrom web
```
* To ask queries from the bot, just tag the bot and ask your question.
```text theme={null}
@botname
```
π Happy Chatting! π
# β FAQs
Source: https://llm-tools.mintlify.app/get-started/faq
Collections of all the frequently asked questions
```ts index.ts theme={null}
import 'dotenv/config';
import { RAGApplicationBuilder } from '@llm-tools/embedjs';
import { Mistral } from '@llm-tools/embedjs-mistral';
import { WebLoader } from '@llm-tools/embedjs-loader-web';
import { HNSWDb } from '@llm-tools/embedjs-hnswlib';
const llmApplication = await new RAGApplicationBuilder()
.setModel(new Mistral({ modelName: 'mistral-medium' }))
.setVectorDatabase(new HNSWDb())
.build();
await llmApplication.addLoader(new WebLoader({ urlOrContent: 'https://en.wikipedia.org/wiki/Tesla,_Inc.' }));
console.log(await llmApplication.query('Who founded Tesla?'));
```
Use the model `gpt-4o` provided my openai.
```ts index.ts theme={null}
import 'dotenv/config';
import { RAGApplicationBuilder } from '@llm-tools/embedjs';
import { OpenAi, OpenAiEmbeddings } from '@llm-tools/embedjs-openai';
import { WebLoader } from '@llm-tools/embedjs-loader-web';
import { HNSWDb } from '@llm-tools/embedjs-hnswlib';
const llmApplication = await new RAGApplicationBuilder()
.setModel(new OpenAi({ modelName: 'gpt-4o' }))
.setEmbeddingModel(new OpenAiEmbeddings())
.setVectorDatabase(new HNSWDb())
.build();
await llmApplication.addLoader(new WebLoader({ urlOrContent: 'https://en.wikipedia.org/wiki/Tesla,_Inc.' }));
console.log(await llmApplication.query('Who founded Tesla?'));
```
```ts index.ts theme={null}
import { RAGApplicationBuilder } from '@llm-tools/embedjs';
import { OllamaEmbeddings } from '@llm-tools/embedjs-ollama';
import { WebLoader } from '@llm-tools/embedjs-loader-web';
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' }))
.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?')
```
#### Still have questions?
If docs aren't sufficient, please feel free to reach out to us using one of the following methods:
# π Introduction
Source: https://llm-tools.mintlify.app/get-started/introduction
## What is EmbedJs?
EmbedJs is an Open Source Framework that makes it easy to create and deploy personalized AI apps. At its core, EmbedJs follows the design principle of being *"Conventional but Configurable"* to serve both software engineers and machine learning engineers.
EmbedJs streamlines the creation of personalized LLM applications, offering a seamless process for managing various types of unstructured data. It efficiently segments data into manageable chunks, generates relevant embeddings, and stores them in a vector database for optimized retrieval. With a suite of diverse APIs, it enables users to extract contextual information, find precise answers, or engage in interactive chat conversations, all tailored to their own data.
## Who is EmbedJs for?
EmbedJs is designed for a diverse range of users, from AI professionals like Data Scientists and Machine Learning Engineers to those just starting their AI journey, including college students, independent developers, and hobbyists. Essentially, it's for anyone with an interest in AI, regardless of their expertise level.
Our APIs are user-friendly yet adaptable, enabling beginners to effortlessly create LLM-powered applications with as few as 7 lines of code. At the same time, we offer extensive customization options for every aspect of building a personalized AI application. This includes the choice of LLMs, vector databases, loaders and chunkers, and more.
Our platform's clear and well-structured abstraction layers ensure that users can tailor the system to meet their specific needs, whether they're crafting a simple project or a complex, nuanced AI application.
## Why Use EmbedJs?
Developing a personalized AI application for production use presents numerous complexities, such as:
* Integrating and indexing data from diverse sources.
* Determining optimal data chunking methods for each source.
* Synchronizing the RAG pipeline with regularly updated data sources.
* Implementing efficient data storage in a vector store.
* Deciding whether to include metadata with document chunks.
* Configuring Large Language Models (LLMs).
* Selecting effective prompts.
EmbedJs is designed to simplify these tasks, offering conventional yet customizable APIs. Our solution handles the intricate processes of loading, chunking, indexing, and retrieving data. This enables you to concentrate on aspects that are crucial for your specific use case or business objectives, ensuring a smoother and more focused development process.
## How it works?
EmbedJs makes it easy to add data to your RAG pipeline with these straightforward steps:
1. **Automatic Data Handling**: It automatically recognizes the data type and loads it.
2. **Efficient Data Processing**: The system creates embeddings for key parts of your data.
3. **Flexible Data Storage**: You get to choose where to store this processed data in a vector database.
When a user asks a question, whether for chatting, searching, or querying, EmbedJs simplifies the response process:
1. **Query Processing**: It turns the user's question into embeddings.
2. **Document Retrieval**: These embeddings are then used to find related documents in the database.
3. **Answer Generation**: The related documents are used by the LLM to craft a precise answer.
With EmbedJs, you donβt have to worry about the complexities of building a personalized AI application. It offers an easy-to-use interface for developing applications with any kind of data.
## Getting started
Checkout our [quickstart guide](/get-started/quickstart) to start your first AI application.
## Support
Feel free to reach out to us if you have ideas, feedback or questions that we can help out with.
## Contribute
* [GitHub](https://github.com/llm-tools/embedjs)
* [Contribution docs](/contribution/dev)
# β‘ Quickstart
Source: https://llm-tools.mintlify.app/get-started/quickstart
π‘ Create an AI app on your own data in a minute
## Installation
First install the NodeJs package:
```bash theme={null}
npm i @llm-tools/embedjs
```
Once you have installed the package, depending upon your preference you can either use:
This includes Open source LLMs like Mistral, Llama, etc.
Free to use, and runs locally on your machine.
This includes paid LLMs like GPT 4, Claude, etc.
Cost money and are accessible via an API.
## 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.
```ts ollama_demo.ts theme={null}
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](/components/embeddings/huggingface) and [here](/components/llms/huggingface).
## Paid Models
In this section, we will use both an LLM and embedding model from OpenAI.
```ts openai_demo.ts theme={null}
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:
* [Introduction](/get-started/introduction)
* [Customization](/components/introduction)
* [Use cases](/use-cases/introduction)
* [Deployment](/get-started/deployment)
# π οΈ LangSmith
Source: https://llm-tools.mintlify.app/integration/langsmith
Integrate with Langsmith to debug and monitor your LLM app
EmbedJs now supports integration with [LangSmith](https://www.langchain.com/langsmith).
To use LangSmith, you need to do the following steps.
1. Have an account on LangSmith and keep the environment variables in handy
2. Set the environment variables in your app so that EmbedJs has context about it.
3. Just use EmbedJs and everything will be logged to LangSmith, so that you can better test and monitor your application.
Let's cover each step in detail.
* First make sure that you have created a LangSmith account and have all the necessary variables handy. LangSmith has a [good documentation](https://docs.smith.langchain.com/) on how to get started with their service.
* Once you have setup the account, we will need the following environment variables
```bash theme={null}
# Setting environment variable for LangChain Tracing V2 integration.
export LANGCHAIN_TRACING_V2=true
# Setting the API endpoint for LangChain.
export LANGCHAIN_ENDPOINT=https://api.smith.langchain.com
# Replace '' with your LangChain API key.
export LANGCHAIN_API_KEY=
# Replace '' with your LangChain project name, or it defaults to "default".
export LANGCHAIN_PROJECT= # if not specified, defaults to "default"
```
* Now create an app using EmbedJs and everything will be automatically visible in LangSmith automatically.
```ts theme={null}
import { RAGApplicationBuilder } from '@llm-tools/embedjs';
import { OpenAiEmbeddings } from '@llm-tools/embedjs-openai';
//Replace this with your OpenAI key
process.env.OPENAI_API_KEY = "sk-xxxx"
//Build a new application
const ragApplication = await new RAGApplicationBuilder()
.setModel(SIMPLE_MODELS.OPENAI_GPT4_O)
.setEmbeddingModel(new OpenAiEmbeddings())
.build();
//Add new documents
ragApplication.addLoader('https://www.forbes.com/profile/elon-musk')
ragApplication.addLoader('https://en.wikipedia.org/wiki/Elon_Musk')
//Query your app
await ragApplication.query('What is the net worth of Elon Musk today?')
```
* Now the entire log for this will be visible in langsmith.
# π Release Notes
Source: https://llm-tools.mintlify.app/product/release-notes
# π€ Chatbots
Source: https://llm-tools.mintlify.app/use-cases/chatbots
Chatbots, especially those powered by Large Language Models (LLMs), have a wide range of use cases, significantly enhancing various aspects of business, education, and personal assistance. Here are some key applications:
* **Customer Service**: Automating responses to common queries and providing 24/7 support.
* **Education**: Offering personalized tutoring and learning assistance.
* **E-commerce**: Assisting in product discovery, recommendations, and transactions.
* **Content Management**: Aiding in writing, summarizing, and organizing content.
* **Data Analysis**: Extracting insights from large datasets.
* **Language Translation**: Providing real-time multilingual support.
* **Mental Health**: Offering preliminary mental health support and conversation.
* **Entertainment**: Engaging users with games, quizzes, and humorous chats.
* **Accessibility Aid**: Enhancing information and service access for individuals with disabilities.
EmbedJs provides the right set of tools to create chatbots for the above use cases. Refer to the following examples of chatbots on and you can built on top of these examples:
Enhance your Slack workspace with a specialized bot.
# π§± Introduction
Source: https://llm-tools.mintlify.app/use-cases/introduction
## Overview
You can use EmbedJs to create the following usecases:
* [Chatbots](/use-cases/chatbots)
* [Question Answering](/use-cases/question-answering)
* [Semantic Search](/use-cases/semantic-search)
# β Question Answering
Source: https://llm-tools.mintlify.app/use-cases/question-answering
Utilizing large language models (LLMs) for question answering is a transformative application, bringing significant benefits to various real-world situations. EmbedJs extensively supports tasks related to question answering, including summarization, content creation, language translation, and data analysis. The versatility of question answering with LLMs enables solutions for numerous practical applications such as:
* **Educational Aid**: Enhancing learning experiences and aiding with homework
* **Customer Support**: Addressing and resolving customer queries efficiently
* **Research Assistance**: Facilitating academic and professional research endeavors
* **Healthcare Information**: Providing fundamental medical knowledge
* **Technical Support**: Resolving technology-related inquiries
* **Legal Information**: Offering basic legal advice and information
* **Business Insights**: Delivering market analysis and strategic business advice
* **Language Learning** Assistance: Aiding in understanding and translating languages
* **Travel Guidance**: Supplying information on travel and hospitality
* **Content Development**: Assisting authors and creators with research and idea generation
## Example: Build a Q\&A System with EmbedJs for Next.JS
Quickly create a RAG pipeline to answer queries about the [Next.JS Framework](https://nextjs.org/) using EmbedJs tools.
### Step 1: Set Up Your RAG Pipeline
First, let's create your RAG pipeline. Open your NodeJs application and add the following code:
```ts Create pipeline theme={null}
import { RAGApplicationBuilder } from '@llm-tools/embedjs';
import { OpenAi } from '@llm-tools/embedjs-openai';
import { HNSWDb } from '@llm-tools/embedjs-hnswlib';
const app = await new RAGApplicationBuilder()
.setModel(SIMPLE_MODELS.OPENAI_GPT4_O)
.setEmbeddingModel(new OpenAiEmbeddings())
.setVectorDatabase(new HNSWDb())
.build();
```
This initializes your application.
### Step 2: Populate Your Pipeline with Data
Now, let's add data to your pipeline. We'll include the Next.JS website and its documentation:
```ts Ingest data sources theme={null}
import { SitemapLoader } from '@llm-tools/embedjs-loader-sitemap';
//Add Next.JS Website and docs
app.addLoader(new SitemapLoader({ url: "https://nextjs.org/sitemap.xml" }))
//Add Next.JS Forum data
app.addLoader(new SitemapLoader({ url: "https://nextjs-forum.com/sitemap.xml" }))
```
This step incorporates over **15K pages** from the Next.JS website and forum into your pipeline. For more data source options, check the [EmbedJs data sources overview](/components/data-sources/overview).
### Step 3: Local Testing of Your Pipeline
Test the pipeline on your local machine:
```ts Query App theme={null}
app.query("Summarize the features of Next.js 14?")
```
Run this query to see how your pipeline responds with information about Next.js 14.
## Need help?
If you are looking to configure the RAG pipeline further, feel free to checkout the [API reference](/api-reference/pipeline/query).
In case you run into issues, feel free to contact us via any of the following methods:
# π Semantic Search
Source: https://llm-tools.mintlify.app/use-cases/semantic-search
Semantic searching, which involves understanding the intent and contextual meaning behind search queries, is yet another popular use-case of RAG. It has several popular use cases across various domains:
* **Information Retrieval**: Enhances search accuracy in databases and websites
* **E-commerce**: Improves product discovery in online shopping
* **Customer Support**: Powers smarter chatbots for effective responses
* **Content Discovery**: Aids in finding relevant media content
* **Knowledge Management**: Streamlines document and data retrieval in enterprises
* **Healthcare**: Facilitates medical research and literature search
* **Legal Research**: Assists in legal document and case law search
* **Academic Research**: Aids in academic paper discovery
* **Language Processing**: Enables multilingual search capabilities
EmbedJs offers a simple yet customizable `search()` API that you can use for semantic search. See the example in the next section to know more.
## Example: Semantic Search over Next.JS Website + Forum
### Step 1: Set Up Your RAG Pipeline
First, let's create your RAG pipeline. Open your NodeJs application and add the following code:
```ts Create pipeline theme={null}
import { RAGApplicationBuilder } from '@llm-tools/embedjs';
import { OpenAiEmbeddings } from '@llm-tools/embedjs-openai';
import { HNSWDb } from '@llm-tools/embedjs-hnswlib';
const app = await new RAGApplicationBuilder()
.setModel(SIMPLE_MODELS.OPENAI_GPT4_O)
.setEmbeddingModel(new OpenAiEmbeddings())
.setVectorDatabase(new HNSWDb())
.build();
```
This initializes your application.
### Step 2: Populate Your Pipeline with Data
Now, let's add data to your pipeline. We'll include the Next.JS website and its documentation:
```ts Ingest data sources theme={null}
import { SitemapLoader } from '@llm-tools/embedjs-loader-sitemap';
//Add Next.JS Website and docs
app.addLoader(new SitemapLoader({ url: "https://nextjs.org/sitemap.xml" }))
//Add Next.JS Forum data
app.addLoader(new SitemapLoader({ url: "https://nextjs-forum.com/sitemap.xml" }))
```
This step incorporates over **15K pages** from the Next.JS website and forum into your pipeline. For more data source options, check the [EmbedJs data sources overview](/components/data-sources/overview).
### Step 3: Local Testing of Your Pipeline
Test the pipeline on your local machine:
```ts Search App theme={null}
app.search("Summarize the features of Next.js 14?")
/*[
{
'score': 0.99,
'pageContent': 'Next.js 14 | Next.jsBack to BlogThursday, October 26th 2023Next.js 14Posted byLee Robinson@leeerobTim Neutkens@timneutkensAs we announced at Next.js Conf, Next.js 14 is our most focused release with: Turbopack: 5,000 tests passing for App & Pages Router 53% faster local server startup 94% faster code updates with Fast Refresh Server Actions (Stable): Progressively enhanced mutations Integrated with caching & revalidating Simple function calls, or works natively with forms Partial Prerendering',
'metadata': {
'id': '6c8d1a7b-ea34-4927-8823-daa29dcfc5af',
'uniqueLoaderId': '6c8d1a7b-ea34-4927-8823-xba29dcfc5ac',
'source': 'https://nextjs.org/blog/next-14'
}
},
{
'score': 0.98,
'pageContent': 'Next.js 13.3 | Next.jsBack to BlogThursday, April 6th 2023Next.js 13.3Posted byDelba de Oliveira@delba_oliveiraTim Neutkens@timneutkensNext.js 13.3 adds popular community-requested features, including: File-Based Metadata API: Dynamically generate sitemaps, robots, favicons, and more. Dynamic Open Graph Images: Generate OG images using JSX, HTML, and CSS. Static Export for App Router: Static / Single-Page Application (SPA) support for Server Components. Parallel Routes and Interception: Advanced',
'metadata': {
'id': '6c8d1a7b-ea34-4927-8823-daa29dcfc5a1',
'uniqueLoaderId': '6c8d1a7b-ea34-4927-8823-xba29dcfc5ae',
'source': 'https://nextjs.org/blog/next-13-3'
}
},
{
'score': 0.98,
'pageContent': 'Upgrading: Version 14 | Next.js MenuUsing App RouterFeatures available in /appApp Router.UpgradingVersion 14Version 14 Upgrading from 13 to 14 To update to Next.js version 14, run the following command using your preferred package manager: Terminalnpm i next@latest react@latest react-dom@latest eslint-config-next@latest Terminalyarn add next@latest react@latest react-dom@latest eslint-config-next@latest Terminalpnpm up next react react-dom eslint-config-next -latest Terminalbun add next@latest',
'metadata': {
'id': '6c8d1a7b-ea34-4927-8823-daa29dcfc5a2',
'uniqueLoaderId': '6c8d1a7b-ea34-4927-8823-xba29dcfc5ad',
'source': 'https://nextjs.org/docs/app/building-your-application/upgrading/version-14'
}
}
]*/
```
The `source` key contains the url of the document that yielded that document chunk.
If you are interested in configuring the search further, refer to our [API documentation](/api-reference/pipeline/search).
***
This guide will help you swiftly set up a semantic search pipeline with EmbedJs, making it easier to access and analyze specific information from large data sources.
## Need help?
In case you run into issues, feel free to contact us via any of the following methods: