Skip to content

Commit

Permalink
Merge pull request #73 from llm-tools/mongodb-vector
Browse files Browse the repository at this point in the history
Mongodb vector database
  • Loading branch information
adhityan authored Jun 7, 2024
2 parents 5dbde53 + 9546107 commit 2db29e5
Show file tree
Hide file tree
Showing 14 changed files with 556 additions and 152 deletions.
37 changes: 32 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ The author(s) are looking to add core maintainers for this opensource project. R
- [HNSWLib](#hnswlib)
- [Weaviate](#weaviate)
- [Qdrant](#qdrant)
- [MongoDB](#mongodb)
- [Bring your own database](#bring-your-own-database)
- [More databases coming soon](#more-databases-coming-soon)
- [Caches](#caches)
Expand Down Expand Up @@ -902,6 +903,34 @@ import { QdrantDb } from '@llm-tools/embedjs/vectorDb/qdrant';
.setVectorDb(new QdrantDb({ apiKey: '...'; url: '...'; clusterName: '...' }))
```

## MongoDB

[MongoDB](https://www.mongodb.com/products/platform/atlas-vector-search) is an open source document database. They offer a managed cloud offering **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)

**Note:** 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.

**Note:** You will need to add a users separately and allow IP access from your relevant development and production environments.

- Set MongoDB database as your choice of `vectorDb`

```TS
import { MongoDb } from '@llm-tools/embedjs/vectorDb/mongodb';

.setVectorDb(
new MongoDb({
connectionString: 'mongodb+srv://<username>:<password>@<url>',
}),
)
```

**Note:** you can also optionally configure the database and collection name the library will use with the constructor parameters `dbName` and `collectionName`. Default values are used if these are not provided.

## Bring your own database

You can pass along your vector database to the `setVectorDb` method by implementing the interface `BaseDb`. Here's how that would look like -
Expand Down Expand Up @@ -1046,11 +1075,9 @@ export LANGCHAIN_API_KEY="<api key>"

Here's a list of projects / examples built with RagKit

| **Project** | **Description** |
| -------------------------------------------------------------------------------- | ----------------------------------------------------------------------- |
| [nestjs-embedjs-template](https://github.com/llm-tools/nestjs-embedjs-template) | A NestJS server side template |
| [nextjs-chatbot-template](https://github.com/llm-tools/chat-bot-nextjs-template) | A NextJS chat template - including a chat UI |
| [slack-bot](https://github.com/llm-tools/slack-bot-template) | A slack bot that can answer questions based on learnt confluence spaces |
| **Project** | **Description** |
| ------------------------------------------------------------ | ---------------------------------------------------------------------- |
| [slack-bot](https://github.com/llm-tools/slack-bot-template) | A NestJs based slack bot that can answer questions based on confluence |

# Contributing

Expand Down
2 changes: 1 addition & 1 deletion examples/chroma/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const llmApplication = await new RAGApplicationBuilder()

await llmApplication.addLoader(new YoutubeLoader({ videoIdOrUrl: 'pQiT2U5E9tI' }));
await llmApplication.addLoader(new SitemapLoader({ url: 'https://tesla-info.com/sitemap.xml' }));
await llmApplication.addLoader(new WebLoader({ url: 'https://en.wikipedia.org/wiki/Tesla,_Inc.' }));
await llmApplication.addLoader(new WebLoader({ urlOrContent: 'https://en.wikipedia.org/wiki/Tesla,_Inc.' }));

console.log((await llmApplication.query('Who founded Tesla?')).result);
// The founder of Tesla is Elon Musk. He co-founded the company with JB Straubel, Martin Eberhard, Marc Tarpenning, and Ian Wright in 2003. Elon Musk is also the CEO of SpaceX and Neuralink.
Expand Down
2 changes: 1 addition & 1 deletion examples/cohere/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const llmApplication = await new RAGApplicationBuilder()

await llmApplication.addLoader(new YoutubeLoader({ videoIdOrUrl: 'pQiT2U5E9tI' }));
await llmApplication.addLoader(new SitemapLoader({ url: 'https://tesla-info.com/sitemap.xml' }));
await llmApplication.addLoader(new WebLoader({ url: 'https://en.wikipedia.org/wiki/Tesla,_Inc.' }));
await llmApplication.addLoader(new WebLoader({ urlOrContent: 'https://en.wikipedia.org/wiki/Tesla,_Inc.' }));

console.log((await llmApplication.query('Who founded Tesla?')).result);
// The founder of Tesla is Elon Musk. He co-founded the company with JB Straubel, Martin Eberhard, Marc Tarpenning, and Ian Wright in 2003. Elon Musk is also the CEO of SpaceX and Neuralink.
Expand Down
2 changes: 1 addition & 1 deletion examples/ollama/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const llmApplication = await new RAGApplicationBuilder()

await llmApplication.addLoader(new YoutubeLoader({ videoIdOrUrl: 'pQiT2U5E9tI' }));
await llmApplication.addLoader(new SitemapLoader({ url: 'https://tesla-info.com/sitemap.xml' }));
await llmApplication.addLoader(new WebLoader({ url: 'https://en.wikipedia.org/wiki/Tesla,_Inc.' }));
await llmApplication.addLoader(new WebLoader({ urlOrContent: 'https://en.wikipedia.org/wiki/Tesla,_Inc.' }));

console.log((await llmApplication.query('Who founded Tesla?')).result);
// The founder of Tesla is Elon Musk. He co-founded the company with JB Straubel, Martin Eberhard, Marc Tarpenning, and Ian Wright in 2003. Elon Musk is also the CEO of SpaceX and Neuralink.
Expand Down
2 changes: 1 addition & 1 deletion examples/pinecone/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const llmApplication = await new RAGApplicationBuilder()

await llmApplication.addLoader(new YoutubeLoader({ videoIdOrUrl: 'pQiT2U5E9tI' }));
await llmApplication.addLoader(new SitemapLoader({ url: 'https://tesla-info.com/sitemap.xml' }));
await llmApplication.addLoader(new WebLoader({ url: 'https://en.wikipedia.org/wiki/Tesla,_Inc.' }));
await llmApplication.addLoader(new WebLoader({ urlOrContent: 'https://en.wikipedia.org/wiki/Tesla,_Inc.' }));

console.log((await llmApplication.query('Who founded Tesla?')).result);
// The founder of Tesla is Elon Musk. He co-founded the company with JB Straubel, Martin Eberhard, Marc Tarpenning, and Ian Wright in 2003. Elon Musk is also the CEO of SpaceX and Neuralink.
Expand Down
2 changes: 1 addition & 1 deletion examples/simple/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const llmApplication = await new RAGApplicationBuilder().setSearchResultCount(30

await llmApplication.addLoader(new YoutubeLoader({ videoIdOrUrl: 'pQiT2U5E9tI' }));
await llmApplication.addLoader(new SitemapLoader({ url: 'https://tesla-info.com/sitemap.xml' }));
await llmApplication.addLoader(new WebLoader({ url: 'https://en.wikipedia.org/wiki/Tesla,_Inc.' }));
await llmApplication.addLoader(new WebLoader({ urlOrContent: 'https://en.wikipedia.org/wiki/Tesla,_Inc.' }));

console.log((await llmApplication.query('Who founded Tesla?')).result);
// The founder of Tesla is Elon Musk. He co-founded the company with JB Straubel, Martin Eberhard, Marc Tarpenning, and Ian Wright in 2003. Elon Musk is also the CEO of SpaceX and Neuralink.
Expand Down
2 changes: 1 addition & 1 deletion examples/vertexai/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const llmApplication = await new RAGApplicationBuilder()

await llmApplication.addLoader(new YoutubeLoader({ videoIdOrUrl: 'pQiT2U5E9tI' }));
await llmApplication.addLoader(new SitemapLoader({ url: 'https://tesla-info.com/sitemap.xml' }));
await llmApplication.addLoader(new WebLoader({ url: 'https://en.wikipedia.org/wiki/Tesla,_Inc.' }));
await llmApplication.addLoader(new WebLoader({ urlOrContent: 'https://en.wikipedia.org/wiki/Tesla,_Inc.' }));

let question = 'Who founded Tesla?';
console.log('[QUESTION]', question);
Expand Down
Loading

0 comments on commit 2db29e5

Please sign in to comment.