llm-tools / embedJs

A NodeJS RAG framework to easily work with LLMs and embeddings
https://llm-tools.mintlify.app/get-started/introduction
Apache License 2.0
334 stars 40 forks source link

DOC: Quickstart does not work #171

Open GhostDog98 opened 1 day ago

GhostDog98 commented 1 day ago

Issue with current documentation:

When using the quickstart code for local development:

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();

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.

And a package.json of:

{
  "dependencies": {
    "@llm-tools/embedjs": "^0.1.18",
    "@llm-tools/embedjs-hnswlib": "^0.1.18",
    "@llm-tools/embedjs-loader-web": "^0.1.18",
    "@llm-tools/embedjs-ollama": "^0.1.18"
  },
  "devDependencies": {
    "typescript": "^5.7.2"
  }
}

Running using npx ts-node main.ts returns:

/Users/user/.npm/_npx/1bf7c3c15bf47d04/node_modules/ts-node/src/index.ts:859
    return new TSError(diagnosticText, diagnosticCodes, diagnostics);
           ^
TSError: ⨯ Unable to compile TypeScript:
main.ts:7:15 - error TS2304: Cannot find name 'Ollama'.

7 .setModel(new Ollama({ modelName: "llama3.2", baseUrl: 'http://localhost:11434' }))
                ~~~~~~
main.ts:12:34 - error TS2353: Object literal may only specify known properties, and 'urlOrContent' does not exist in type 'BaseLoader<Record<string, string | number | boolean>, Record<string, unknown>>'.

12 await ragApplication.addLoader({ urlOrContent: 'https://www.forbes.com/profile/elon-musk' })
                                    ~~~~~~~~~~~~
main.ts:13:34 - error TS2353: Object literal may only specify known properties, and 'urlOrContent' does not exist in type 'BaseLoader<Record<string, string | number | boolean>, Record<string, unknown>>'.

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

    at createTSError (/Users/user/.npm/_npx/1bf7c3c15bf47d04/node_modules/ts-node/src/index.ts:859:12)
    at reportTSError (/Users/user/.npm/_npx/1bf7c3c15bf47d04/node_modules/ts-node/src/index.ts:863:19)
    at getOutput (/Users/user/.npm/_npx/1bf7c3c15bf47d04/node_modules/ts-node/src/index.ts:1077:36)
    at Object.compile (/Users/user/.npm/_npx/1bf7c3c15bf47d04/node_modules/ts-node/src/index.ts:1433:41)
    at Module.m._compile (/Users/user/.npm/_npx/1bf7c3c15bf47d04/node_modules/ts-node/src/index.ts:1617:30)
    at Module._extensions..js (node:internal/modules/cjs/loader:1551:10)
    at Object.require.extensions.<computed> [as .ts] (/Users/user/.npm/_npx/1bf7c3c15bf47d04/node_modules/ts-node/src/index.ts:1621:12)
    at Module.load (node:internal/modules/cjs/loader:1282:32)
    at Function.Module._load (node:internal/modules/cjs/loader:1098:12)
    at TracingChannel.traceSync (node:diagnostics_channel:315:14) {
  diagnosticCodes: [ 2304, 2353, 2353 ]
}

Is there something I am missing?

adhityan commented 12 hours ago

I think Ollama was not imported. You need to replace the line -

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

with

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

I have updated the documentation.