Skip to content

Commit fe77860

Browse files
authored
Merge pull request #227 from mohit-twelvelabs/feat/twelvelabs-integration
feat: add TwelveLabs Marengo embeddings and Pegasus video loader
2 parents 6323eae + 21c2853 commit fe77860

14 files changed

Lines changed: 514 additions & 622 deletions

File tree

docs/components/data-sources/overview.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ We handle the complexity of loading unstructured data from these data sources, a
1717
<Card title="Youtube Video" href="/components/data-sources/youtube-video" />
1818
<Card title="Youtube Channel" href="/components/data-sources/youtube-channel" />
1919
<Card title="Youtube Search" href="/components/data-sources/youtube-search" />
20+
<Card title="TwelveLabs Video" href="/components/data-sources/twelvelabs-video" />
2021
<Card title="DOCX file" href="/components/data-sources/docx" />
2122
<Card title="PPT file" href="/components/data-sources/ppt" />
2223
<Card title="Excel file" href="/components/data-sources/excel" />
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
---
2+
title: '🎬 TwelveLabs Video'
3+
---
4+
5+
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.
6+
7+
- Sign up for an account with TwelveLabs and grab an API key. There's a generous free tier at [twelvelabs.io](https://twelvelabs.io).
8+
9+
- Set the key in the environment variable `TWELVELABS_API_KEY` (or pass it directly to the loader).
10+
11+
```bash
12+
TWELVELABS_API_KEY="<YOUR_KEY>"
13+
```
14+
15+
## Install TwelveLabs addon
16+
17+
```bash
18+
npm install @llm-tools/embedjs-twelvelabs
19+
```
20+
21+
## Usage
22+
23+
```ts
24+
import { RAGApplicationBuilder } from '@llm-tools/embedjs';
25+
import { OpenAiEmbeddings } from '@llm-tools/embedjs-openai';
26+
import { HNSWDb } from '@llm-tools/embedjs-hnswlib';
27+
import { TwelveLabsVideoLoader } from '@llm-tools/embedjs-twelvelabs';
28+
29+
const app = await new RAGApplicationBuilder()
30+
.setModel(SIMPLE_MODELS.OPENAI_GPT4_O)
31+
.setEmbeddingModel(new OpenAiEmbeddings())
32+
.setVectorDatabase(new HNSWDb())
33+
.build();
34+
35+
app.addLoader(new TwelveLabsVideoLoader({ url: 'https://example.com/video.mp4' }))
36+
```
37+
38+
You can customise the analysis with an optional `prompt`, `model` (`pegasus1.2` or `pegasus1.5`) and `maxTokens`:
39+
40+
```ts
41+
app.addLoader(new TwelveLabsVideoLoader({
42+
url: 'https://example.com/video.mp4',
43+
prompt: 'Summarize the key moments in this video.',
44+
model: 'pegasus1.2',
45+
maxTokens: 2048,
46+
}))
47+
```

docs/components/embeddings/overview.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ EmbedJs supports several embedding models from the following providers:
1212
<Card title="Huggingface" href="/components/embeddings/huggingface" />
1313
<Card title="Ollama" href="/components/embeddings/ollama" />
1414
<Card title="LlamaCpp" href="/components/embeddings/llama-cpp" />
15+
<Card title="TwelveLabs (Marengo)" href="/components/embeddings/twelvelabs" />
1516
</CardGroup>
1617

1718
<br/ >
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
---
2+
title: 'TwelveLabs (Marengo)'
3+
---
4+
5+
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.
6+
7+
Here's what you have to do to use it -
8+
9+
- Sign up for an account with TwelveLabs and grab an API key. There's a generous free tier at [twelvelabs.io](https://twelvelabs.io).
10+
11+
- Set the key in the environment variable `TWELVELABS_API_KEY` (or pass it directly to the constructor).
12+
13+
```bash
14+
TWELVELABS_API_KEY="<YOUR_KEY>"
15+
```
16+
17+
## Install TwelveLabs addon
18+
19+
```bash
20+
npm install @llm-tools/embedjs-twelvelabs
21+
```
22+
23+
## Usage
24+
25+
```ts
26+
import { RAGApplicationBuilder } from '@llm-tools/embedjs';
27+
import { MarengoEmbeddings } from '@llm-tools/embedjs-twelvelabs';
28+
import { HNSWDb } from '@llm-tools/embedjs-hnswlib';
29+
30+
const app = await new RAGApplicationBuilder()
31+
.setEmbeddingModel(new MarengoEmbeddings())
32+
```
33+
34+
You can also pass the API key explicitly:
35+
36+
```ts
37+
new MarengoEmbeddings({ apiKey: 'YOUR_KEY' })
38+
```

docs/mint.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@
8585
"components/data-sources/xml",
8686
"components/data-sources/directory",
8787
"components/data-sources/image",
88+
"components/data-sources/twelvelabs-video",
8889
"components/data-sources/custom"
8990
]
9091
}
@@ -139,7 +140,8 @@
139140
"components/embeddings/cohere",
140141
"components/embeddings/ollama",
141142
"components/embeddings/huggingface",
142-
"components/embeddings/vertexai"
143+
"components/embeddings/vertexai",
144+
"components/embeddings/twelvelabs"
143145
]
144146
}
145147
]
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# embedjs-twelvelabs
2+
3+
<p>
4+
<a href="https://www.npmjs.com/package/@llm-tools/embedjs" target="_blank"><img alt="NPM Version" src="https://img.shields.io/npm/v/%40llm-tools/embedjs?style=for-the-badge"></a>
5+
<a href="https://www.npmjs.com/package/@llm-tools/embedjs" target="_blank"><img alt="License" src="https://img.shields.io/npm/l/%40llm-tools%2Fembedjs?style=for-the-badge"></a>
6+
</p>
7+
8+
This package extends [embedJs](https://www.npmjs.com/package/@llm-tools/embedjs) with [TwelveLabs](https://twelvelabs.io) video understanding:
9+
10+
- **`MarengoEmbeddings`** — multimodal embeddings from the Marengo model (512 dimensions), usable as a drop in embedding model.
11+
- **`TwelveLabsVideoLoader`** — a data source that analyses a video with the Pegasus model and loads the resulting description into your RAG application.
12+
13+
Refer to the [embedJs documentation](https://llm-tools.mintlify.app) for more details.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import baseConfig from '../../eslint.config.js';
2+
import parser from '@nx/eslint-plugin';
3+
4+
export default [
5+
...baseConfig,
6+
{
7+
files: ['**/*.json'],
8+
rules: {
9+
'@nx/dependency-checks': [
10+
'error',
11+
{
12+
ignoredFiles: ['{projectRoot}/eslint.config.{js,cjs,mjs}'],
13+
},
14+
],
15+
},
16+
languageOptions: {
17+
parser,
18+
},
19+
},
20+
];
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{
2+
"name": "@llm-tools/embedjs-twelvelabs",
3+
"version": "0.1.31",
4+
"description": "Enable usage of TwelveLabs Marengo embeddings and Pegasus video understanding with embedjs",
5+
"dependencies": {
6+
"@langchain/textsplitters": "^1.0.0",
7+
"@llm-tools/embedjs-interfaces": "0.1.31",
8+
"@llm-tools/embedjs-utils": "0.1.31",
9+
"debug": "^4.4.3",
10+
"md5": "^2.3.0",
11+
"twelvelabs-js": "^1.2.8"
12+
},
13+
"type": "module",
14+
"main": "./src/index.js",
15+
"license": "Apache-2.0",
16+
"publishConfig": {
17+
"access": "public"
18+
},
19+
"keywords": [
20+
"llm",
21+
"ai",
22+
"twelvelabs",
23+
"marengo",
24+
"pegasus",
25+
"video",
26+
"multimodal",
27+
"embeddings",
28+
"vectorstores",
29+
"rag"
30+
],
31+
"author": "K V Adhityan",
32+
"bugs": {
33+
"url": "https://github.com/llm-tools/embedjs/issues"
34+
},
35+
"homepage": "https://github.com/llm-tools/embedjs#readme",
36+
"repository": {
37+
"type": "git",
38+
"url": "git+https://github.com/llm-tools/embedjs.git"
39+
}
40+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"name": "embedjs-twelvelabs",
3+
"$schema": "../../node_modules/nx/schemas/project-schema.json",
4+
"sourceRoot": "models/embedjs-twelvelabs/src",
5+
"projectType": "library",
6+
"tags": [],
7+
"targets": {
8+
"build": {
9+
"executor": "@nx/js:tsc",
10+
"outputs": ["{options.outputPath}"],
11+
"options": {
12+
"outputPath": "dist/embedjs-twelvelabs",
13+
"main": "models/embedjs-twelvelabs/src/index.ts",
14+
"tsConfig": "models/embedjs-twelvelabs/tsconfig.json",
15+
"assets": ["models/embedjs-twelvelabs/*.md"]
16+
}
17+
}
18+
}
19+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from './marengo-embeddings.js';
2+
export * from './twelvelabs-video-loader.js';

0 commit comments

Comments
 (0)