The .query() method empowers developers to ask questions and receive relevant answers through a user-friendly query API. Function signature is given below:

Parameters

userQuery
string
required

Question to ask

conversationId
bool

The conversation ID to which the query belongs in case this is a chatbot scenario

customContext
Chunk[]

In case you want to pass along your own context information. Passing this parameter disables the default context generation.

Returns

id
string

Unique identifier for the query response in a conversation

timestamp
Date

Unique identifier for the query response in a conversation

content
string

Unique identifier for the query response in a conversation

sources
SourceDetail[]

The individual sources that were used to generate the answer

tokenUse
object

The number of tokens used to answer the query

Usage

If you want to get the answer to question and return both answer and citations, use the following code snippet:

Code Example
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?')

/*



*/