11import createDebugMessages from 'debug' ;
22
3- import { RAGEmbedding } from './rag-embedding.js' ;
43import { RAGApplicationBuilder } from './rag-application-builder.js' ;
54import {
65 AddLoaderReturn ,
@@ -14,6 +13,7 @@ import {
1413 QueryResponse ,
1514 SIMPLE_MODELS ,
1615 DEFAULT_INSERT_BATCH_SIZE ,
16+ BaseEmbeddings ,
1717} from '@llm-tools/embedjs-interfaces' ;
1818import { cleanString , getUnique } from '@llm-tools/embedjs-utils' ;
1919
@@ -24,12 +24,14 @@ export class RAGApplication {
2424 private readonly searchResultCount : number ;
2525 private readonly systemMessage : string ;
2626 private readonly vectorDatabase : BaseVectorDatabase ;
27+ private readonly embeddingModel : BaseEmbeddings ;
2728 private readonly store : BaseStore ;
2829 private loaders : BaseLoader [ ] ;
2930 private model : BaseModel ;
3031
3132 constructor ( llmBuilder : RAGApplicationBuilder ) {
3233 if ( ! llmBuilder . getEmbeddingModel ( ) ) throw new Error ( 'Embedding model must be set!' ) ;
34+ this . embeddingModel = llmBuilder . getEmbeddingModel ( ) ;
3335
3436 this . storeConversationsToDefaultThread = llmBuilder . getParamStoreConversationsToDefaultThread ( ) ;
3537 this . store = llmBuilder . getStore ( ) ;
@@ -55,7 +57,7 @@ export class RAGApplication {
5557 * LLM based on the configuration provided
5658 */
5759 public async init ( llmBuilder : RAGApplicationBuilder ) {
58- await RAGEmbedding . init ( llmBuilder . getEmbeddingModel ( ) ) ;
60+ await this . embeddingModel . init ( ) ;
5961
6062 this . model = await this . getModel ( llmBuilder . getModel ( ) ) ;
6163 if ( ! this . model ) this . debug ( 'No base model set; query function unavailable!' ) ;
@@ -68,7 +70,7 @@ export class RAGApplication {
6870 this . debug ( 'Initialized LLM class' ) ;
6971 }
7072
71- await this . vectorDatabase . init ( { dimensions : await RAGEmbedding . getEmbedding ( ) . getDimensions ( ) } ) ;
73+ await this . vectorDatabase . init ( { dimensions : await this . embeddingModel . getDimensions ( ) } ) ;
7274 this . debug ( 'Initialized vector database' ) ;
7375
7476 if ( this . store ) {
@@ -117,7 +119,7 @@ export class RAGApplication {
117119 */
118120 private async embedChunks ( chunks : Pick < Chunk , 'pageContent' > [ ] ) {
119121 const texts = chunks . map ( ( { pageContent } ) => pageContent ) ;
120- return RAGEmbedding . getEmbedding ( ) . embedDocuments ( texts ) ;
122+ return this . embeddingModel . embedDocuments ( texts ) ;
121123 }
122124
123125 /**
@@ -352,7 +354,7 @@ export class RAGApplication {
352354 * only the number of results specified by the `searchResultCount` property.
353355 */
354356 public async getEmbeddings ( cleanQuery : string ) {
355- const queryEmbedded = await RAGEmbedding . getEmbedding ( ) . embedQuery ( cleanQuery ) ;
357+ const queryEmbedded = await this . embeddingModel . embedQuery ( cleanQuery ) ;
356358 const unfilteredResultSet = await this . vectorDatabase . similaritySearch (
357359 queryEmbedded ,
358360 this . searchResultCount + 10 ,
0 commit comments