langchain-rag-chat 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +9 -0
- package/dist/core/RAGChat.d.ts +104 -0
- package/dist/core/index.d.ts +2 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +26964 -0
- package/dist/loaders/index.d.ts +6 -0
- package/dist/loaders/load.d.ts +31 -0
- package/dist/loaders/pdfLoader.d.ts +12 -0
- package/dist/loaders/webLoader.d.ts +16 -0
- package/dist/models/chatModel.d.ts +2 -0
- package/dist/models/embedModel.d.ts +13 -0
- package/dist/models/index.d.ts +3 -0
- package/dist/prompts/answerPrompt.d.ts +6 -0
- package/dist/prompts/classifyPrompt.d.ts +7 -0
- package/dist/prompts/index.d.ts +6 -0
- package/dist/prompts/multiQueryPrompt.d.ts +7 -0
- package/dist/utils/concurrency.d.ts +3 -0
- package/dist/utils/index.d.ts +1 -0
- package/package.json +46 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Yzby
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { createChatModel, EmbeddingModelOptions } from '../models';
|
|
2
|
+
import { Document } from '@langchain/core/documents';
|
|
3
|
+
import { VectorStore, VectorStoreRetrieverInput } from '@langchain/core/vectorstores';
|
|
4
|
+
import { Embeddings } from '@langchain/core/embeddings';
|
|
5
|
+
import { LoadOptions, CustomLoder } from '../loaders';
|
|
6
|
+
import { ChatOpenAIFields } from '@langchain/openai';
|
|
7
|
+
import { RunnableConfig, RunnableLike } from '@langchain/core/runnables';
|
|
8
|
+
export type VectorStoreFactory = (embeddings: Embeddings) => VectorStore;
|
|
9
|
+
export type RAGStep = "init" | "classification" | "loader" | "embedding" | "vectorStore" | "retrieve" | "compress" | "answer";
|
|
10
|
+
export interface RAGOptions<Q extends string> {
|
|
11
|
+
chatModel: ChatOpenAIFields;
|
|
12
|
+
/**
|
|
13
|
+
* Customized storage solution
|
|
14
|
+
* @default MemoryVectorStore
|
|
15
|
+
*/
|
|
16
|
+
vectorStore?: VectorStoreFactory;
|
|
17
|
+
embeddings?: Embeddings;
|
|
18
|
+
embeddingModelOptions?: EmbeddingModelOptions;
|
|
19
|
+
/**
|
|
20
|
+
* Enhance Prompt
|
|
21
|
+
* @default 3
|
|
22
|
+
* @example
|
|
23
|
+
* input: What is a computed property
|
|
24
|
+
* result:
|
|
25
|
+
* Explain the concept of a computed property in software development.
|
|
26
|
+
* What is the difference between a computed property and a regular method or getter?
|
|
27
|
+
* How do derived properties calculate and cache their values in reactive programming frameworks?
|
|
28
|
+
*/
|
|
29
|
+
enhancePrompt?: number;
|
|
30
|
+
/**
|
|
31
|
+
* question Category array
|
|
32
|
+
*/
|
|
33
|
+
category?: Q[];
|
|
34
|
+
enableClassification?: boolean;
|
|
35
|
+
/**
|
|
36
|
+
* Question Categorization ['biology', 'All animals and plants on Earth']
|
|
37
|
+
*/
|
|
38
|
+
questionCategory?: [Q, string][];
|
|
39
|
+
onStep?: (step: RAGStep, payload?: any) => void;
|
|
40
|
+
/**
|
|
41
|
+
* Retrieve Pre Processing
|
|
42
|
+
*/
|
|
43
|
+
preRetrieve?: RunnableLike;
|
|
44
|
+
/**
|
|
45
|
+
* Retrieve Post Processing
|
|
46
|
+
*/
|
|
47
|
+
postRetrieve?: RunnableLike;
|
|
48
|
+
loder?: CustomLoder;
|
|
49
|
+
}
|
|
50
|
+
export interface InputQuestion {
|
|
51
|
+
question: string;
|
|
52
|
+
k?: number;
|
|
53
|
+
}
|
|
54
|
+
export declare class RAGChat<Q extends string> {
|
|
55
|
+
vectorStore: VectorStore;
|
|
56
|
+
chatModel: ReturnType<typeof createChatModel>;
|
|
57
|
+
embeddings: Embeddings;
|
|
58
|
+
enhancePrompt: number;
|
|
59
|
+
category: Q[];
|
|
60
|
+
questionCategory: [Q, string][];
|
|
61
|
+
private onStep;
|
|
62
|
+
private chain;
|
|
63
|
+
private retrievalChain;
|
|
64
|
+
private loder;
|
|
65
|
+
preRetrieve: RunnableLike | null;
|
|
66
|
+
postRetrieve: RunnableLike | null;
|
|
67
|
+
enableClassification: boolean;
|
|
68
|
+
constructor(options: RAGOptions<Q>);
|
|
69
|
+
load(loadResource: {
|
|
70
|
+
type: Q;
|
|
71
|
+
loadOptions: LoadOptions;
|
|
72
|
+
}[]): Promise<void>;
|
|
73
|
+
/**
|
|
74
|
+
* Search Document
|
|
75
|
+
*/
|
|
76
|
+
retrieveDocuments(question: string[], kOrFields?: number | Partial<VectorStoreRetrieverInput<typeof this.vectorStore>>): Promise<Document<Record<string, any>>[]>;
|
|
77
|
+
private createRetrieveProcess;
|
|
78
|
+
private createProcess;
|
|
79
|
+
/**
|
|
80
|
+
* Question Classification
|
|
81
|
+
* @param question
|
|
82
|
+
* @param category
|
|
83
|
+
* @param questionCategory
|
|
84
|
+
* @returns
|
|
85
|
+
*/
|
|
86
|
+
classification(question: string, category?: string[], questionCategory?: [Q, string][]): Promise<Q | "other">;
|
|
87
|
+
/**
|
|
88
|
+
* Question Expand
|
|
89
|
+
* @param question
|
|
90
|
+
* @param queryCount
|
|
91
|
+
* @returns
|
|
92
|
+
*/
|
|
93
|
+
expandQuestion(question: string, queryCount?: number): Promise<string[]>;
|
|
94
|
+
private answer;
|
|
95
|
+
private streamAnswer;
|
|
96
|
+
/**
|
|
97
|
+
* Compression and Deduplication
|
|
98
|
+
* @param docs
|
|
99
|
+
* @returns
|
|
100
|
+
*/
|
|
101
|
+
deduplicateAndCompress(docs: Document[]): Document[];
|
|
102
|
+
invoke(input: string | InputQuestion, options?: RunnableConfig): Promise<any>;
|
|
103
|
+
stream(input: string | InputQuestion, options?: RunnableConfig): AsyncGenerator<string, void, unknown>;
|
|
104
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { RAGChat } from './core';
|
|
2
|
+
export { loadResources, loadPDF, loadWebPage } from './loaders';
|
|
3
|
+
export { createChatModel, createEmbeddingModel } from './models';
|
|
4
|
+
export type { RAGOptions, RAGStep } from './core';
|
|
5
|
+
export type { Resource, LoadOptions, PDFLoader, WebURL, CustomLoder, } from './loaders';
|
|
6
|
+
export type { EmbeddingModelOptions } from './models';
|