langchain 0.1.35 → 0.1.37
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/dist/chains/conversational_retrieval_chain.cjs +61 -19
- package/dist/chains/conversational_retrieval_chain.d.ts +61 -19
- package/dist/chains/conversational_retrieval_chain.js +61 -19
- package/dist/chains/llm_chain.cjs +10 -5
- package/dist/chains/llm_chain.d.ts +10 -5
- package/dist/chains/llm_chain.js +10 -5
- package/dist/chains/openai_functions/base.cjs +2 -0
- package/dist/chains/openai_functions/base.d.ts +2 -0
- package/dist/chains/openai_functions/base.js +2 -0
- package/dist/chains/query_constructor/index.cjs +5 -8
- package/dist/chains/query_constructor/index.d.ts +5 -4
- package/dist/chains/query_constructor/index.js +3 -6
- package/dist/chains/query_constructor/ir.cjs +15 -139
- package/dist/chains/query_constructor/ir.d.ts +1 -138
- package/dist/chains/query_constructor/ir.js +1 -132
- package/dist/chains/query_constructor/prompt.cjs +2 -2
- package/dist/chains/query_constructor/prompt.d.ts +1 -1
- package/dist/chains/query_constructor/prompt.js +1 -1
- package/dist/chains/retrieval_qa.cjs +23 -14
- package/dist/chains/retrieval_qa.d.ts +23 -14
- package/dist/chains/retrieval_qa.js +23 -14
- package/dist/document_loaders/fs/unstructured.cjs +1 -1
- package/dist/document_loaders/fs/unstructured.js +1 -1
- package/dist/document_loaders/web/browserbase.cjs +87 -0
- package/dist/document_loaders/web/browserbase.d.ts +49 -0
- package/dist/document_loaders/web/browserbase.js +80 -0
- package/dist/document_loaders/web/firecrawl.cjs +88 -0
- package/dist/document_loaders/web/firecrawl.d.ts +48 -0
- package/dist/document_loaders/web/firecrawl.js +81 -0
- package/dist/document_loaders/web/s3.cjs +2 -2
- package/dist/document_loaders/web/s3.js +2 -2
- package/dist/load/import_constants.cjs +2 -0
- package/dist/load/import_constants.js +2 -0
- package/dist/output_parsers/expression.cjs +1 -1
- package/dist/output_parsers/expression.d.ts +1 -1
- package/dist/output_parsers/expression.js +1 -1
- package/dist/retrievers/self_query/base.cjs +3 -136
- package/dist/retrievers/self_query/base.d.ts +1 -69
- package/dist/retrievers/self_query/base.js +1 -134
- package/dist/retrievers/self_query/chroma.cjs +9 -10
- package/dist/retrievers/self_query/chroma.d.ts +1 -1
- package/dist/retrievers/self_query/chroma.js +1 -2
- package/dist/retrievers/self_query/functional.cjs +2 -195
- package/dist/retrievers/self_query/functional.d.ts +1 -87
- package/dist/retrievers/self_query/functional.js +1 -194
- package/dist/retrievers/self_query/index.cjs +9 -13
- package/dist/retrievers/self_query/index.d.ts +11 -8
- package/dist/retrievers/self_query/index.js +7 -11
- package/dist/retrievers/self_query/pinecone.cjs +9 -10
- package/dist/retrievers/self_query/pinecone.d.ts +1 -1
- package/dist/retrievers/self_query/pinecone.js +1 -2
- package/dist/retrievers/self_query/supabase.cjs +28 -30
- package/dist/retrievers/self_query/supabase.d.ts +1 -2
- package/dist/retrievers/self_query/supabase.js +1 -3
- package/dist/retrievers/self_query/supabase_utils.cjs +2 -2
- package/dist/retrievers/self_query/supabase_utils.d.ts +1 -1
- package/dist/retrievers/self_query/supabase_utils.js +1 -1
- package/dist/retrievers/self_query/vectara.cjs +15 -17
- package/dist/retrievers/self_query/vectara.d.ts +1 -2
- package/dist/retrievers/self_query/vectara.js +1 -3
- package/dist/retrievers/self_query/weaviate.cjs +19 -21
- package/dist/retrievers/self_query/weaviate.d.ts +1 -2
- package/dist/retrievers/self_query/weaviate.js +1 -3
- package/dist/smith/config.d.ts +4 -4
- package/dist/storage/in_memory.cjs +2 -81
- package/dist/storage/in_memory.d.ts +1 -49
- package/dist/storage/in_memory.js +1 -80
- package/dist/text_splitter.cjs +15 -727
- package/dist/text_splitter.d.ts +1 -77
- package/dist/text_splitter.js +1 -720
- package/dist/vectorstores/qdrant.cjs +2 -0
- package/dist/vectorstores/qdrant.js +2 -0
- package/document_loaders/web/browserbase.cjs +1 -0
- package/document_loaders/web/browserbase.d.cts +1 -0
- package/document_loaders/web/browserbase.d.ts +1 -0
- package/document_loaders/web/browserbase.js +1 -0
- package/document_loaders/web/firecrawl.cjs +1 -0
- package/document_loaders/web/firecrawl.d.cts +1 -0
- package/document_loaders/web/firecrawl.d.ts +1 -0
- package/document_loaders/web/firecrawl.js +1 -0
- package/package.json +40 -3
- package/dist/retrievers/self_query/utils.cjs +0 -94
- package/dist/retrievers/self_query/utils.d.ts +0 -29
- package/dist/retrievers/self_query/utils.js +0 -85
|
@@ -1,138 +1 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* Represents logical AND operator.
|
|
4
|
-
*/
|
|
5
|
-
export type AND = "and";
|
|
6
|
-
/**
|
|
7
|
-
* Represents logical OR operator.
|
|
8
|
-
*/
|
|
9
|
-
export type OR = "or";
|
|
10
|
-
/**
|
|
11
|
-
* Represents logical NOT operator.
|
|
12
|
-
*/
|
|
13
|
-
export type NOT = "not";
|
|
14
|
-
/**
|
|
15
|
-
* Represents a logical operator which can be AND, OR, or NOT.
|
|
16
|
-
*/
|
|
17
|
-
export type Operator = AND | OR | NOT;
|
|
18
|
-
/**
|
|
19
|
-
* Represents equality comparison operator.
|
|
20
|
-
*/
|
|
21
|
-
export type EQ = "eq";
|
|
22
|
-
/**
|
|
23
|
-
* Represents inequality comparison operator.
|
|
24
|
-
*/
|
|
25
|
-
export type NE = "ne";
|
|
26
|
-
/**
|
|
27
|
-
* Represents less than comparison operator.
|
|
28
|
-
*/
|
|
29
|
-
export type LT = "lt";
|
|
30
|
-
/**
|
|
31
|
-
* Represents greater than comparison operator.
|
|
32
|
-
*/
|
|
33
|
-
export type GT = "gt";
|
|
34
|
-
/**
|
|
35
|
-
* Represents less than or equal to comparison operator.
|
|
36
|
-
*/
|
|
37
|
-
export type LTE = "lte";
|
|
38
|
-
/**
|
|
39
|
-
* Represents greater than or equal to comparison operator.
|
|
40
|
-
*/
|
|
41
|
-
export type GTE = "gte";
|
|
42
|
-
/**
|
|
43
|
-
* Represents a comparison operator which can be EQ, NE, LT, GT, LTE, or
|
|
44
|
-
* GTE.
|
|
45
|
-
*/
|
|
46
|
-
export type Comparator = EQ | NE | LT | GT | LTE | GTE;
|
|
47
|
-
export declare const Operators: {
|
|
48
|
-
[key: string]: Operator;
|
|
49
|
-
};
|
|
50
|
-
export declare const Comparators: {
|
|
51
|
-
[key: string]: Comparator;
|
|
52
|
-
};
|
|
53
|
-
/**
|
|
54
|
-
* Represents the result of visiting an operation or comparison
|
|
55
|
-
* expression.
|
|
56
|
-
*/
|
|
57
|
-
export type VisitorResult = VisitorOperationResult | VisitorComparisonResult;
|
|
58
|
-
/**
|
|
59
|
-
* Represents the result of visiting an operation expression.
|
|
60
|
-
*/
|
|
61
|
-
export type VisitorOperationResult = {
|
|
62
|
-
[operator: string]: VisitorResult[];
|
|
63
|
-
};
|
|
64
|
-
/**
|
|
65
|
-
* Represents the result of visiting a comparison expression.
|
|
66
|
-
*/
|
|
67
|
-
export type VisitorComparisonResult = {
|
|
68
|
-
[attr: string]: {
|
|
69
|
-
[comparator: string]: string | number;
|
|
70
|
-
};
|
|
71
|
-
};
|
|
72
|
-
/**
|
|
73
|
-
* Represents the result of visiting a structured query expression.
|
|
74
|
-
*/
|
|
75
|
-
export type VisitorStructuredQueryResult = {
|
|
76
|
-
filter?: VisitorComparisonResult | VisitorOperationResult;
|
|
77
|
-
};
|
|
78
|
-
/**
|
|
79
|
-
* Abstract class for visiting expressions. Subclasses must implement
|
|
80
|
-
* visitOperation, visitComparison, and visitStructuredQuery methods.
|
|
81
|
-
*/
|
|
82
|
-
export declare abstract class Visitor<T extends VectorStore = VectorStore> {
|
|
83
|
-
VisitOperationOutput: object;
|
|
84
|
-
VisitComparisonOutput: object;
|
|
85
|
-
VisitStructuredQueryOutput: {
|
|
86
|
-
filter?: T["FilterType"];
|
|
87
|
-
};
|
|
88
|
-
abstract allowedOperators: Operator[];
|
|
89
|
-
abstract allowedComparators: Comparator[];
|
|
90
|
-
abstract visitOperation(operation: Operation): this["VisitOperationOutput"];
|
|
91
|
-
abstract visitComparison(comparison: Comparison): this["VisitComparisonOutput"];
|
|
92
|
-
abstract visitStructuredQuery(structuredQuery: StructuredQuery): this["VisitStructuredQueryOutput"];
|
|
93
|
-
}
|
|
94
|
-
/**
|
|
95
|
-
* Abstract class representing an expression. Subclasses must implement
|
|
96
|
-
* the exprName property and the accept method.
|
|
97
|
-
*/
|
|
98
|
-
export declare abstract class Expression {
|
|
99
|
-
abstract exprName: "Operation" | "Comparison" | "StructuredQuery";
|
|
100
|
-
accept(visitor: Visitor): object;
|
|
101
|
-
}
|
|
102
|
-
/**
|
|
103
|
-
* Abstract class representing a filter directive. It extends the
|
|
104
|
-
* Expression class.
|
|
105
|
-
*/
|
|
106
|
-
export declare abstract class FilterDirective extends Expression {
|
|
107
|
-
}
|
|
108
|
-
/**
|
|
109
|
-
* Class representing a comparison filter directive. It extends the
|
|
110
|
-
* FilterDirective class.
|
|
111
|
-
*/
|
|
112
|
-
export declare class Comparison extends FilterDirective {
|
|
113
|
-
comparator: Comparator;
|
|
114
|
-
attribute: string;
|
|
115
|
-
value: string | number;
|
|
116
|
-
exprName: "Comparison";
|
|
117
|
-
constructor(comparator: Comparator, attribute: string, value: string | number);
|
|
118
|
-
}
|
|
119
|
-
/**
|
|
120
|
-
* Class representing an operation filter directive. It extends the
|
|
121
|
-
* FilterDirective class.
|
|
122
|
-
*/
|
|
123
|
-
export declare class Operation extends FilterDirective {
|
|
124
|
-
operator: Operator;
|
|
125
|
-
args?: FilterDirective[] | undefined;
|
|
126
|
-
exprName: "Operation";
|
|
127
|
-
constructor(operator: Operator, args?: FilterDirective[] | undefined);
|
|
128
|
-
}
|
|
129
|
-
/**
|
|
130
|
-
* Class representing a structured query expression. It extends the
|
|
131
|
-
* Expression class.
|
|
132
|
-
*/
|
|
133
|
-
export declare class StructuredQuery extends Expression {
|
|
134
|
-
query: string;
|
|
135
|
-
filter?: FilterDirective | undefined;
|
|
136
|
-
exprName: "StructuredQuery";
|
|
137
|
-
constructor(query: string, filter?: FilterDirective | undefined);
|
|
138
|
-
}
|
|
1
|
+
export * from "@langchain/core/structured_query";
|
|
@@ -1,132 +1 @@
|
|
|
1
|
-
export
|
|
2
|
-
and: "and",
|
|
3
|
-
or: "or",
|
|
4
|
-
not: "not",
|
|
5
|
-
};
|
|
6
|
-
export const Comparators = {
|
|
7
|
-
eq: "eq",
|
|
8
|
-
ne: "ne",
|
|
9
|
-
lt: "lt",
|
|
10
|
-
gt: "gt",
|
|
11
|
-
lte: "lte",
|
|
12
|
-
gte: "gte",
|
|
13
|
-
};
|
|
14
|
-
/**
|
|
15
|
-
* Abstract class for visiting expressions. Subclasses must implement
|
|
16
|
-
* visitOperation, visitComparison, and visitStructuredQuery methods.
|
|
17
|
-
*/
|
|
18
|
-
export class Visitor {
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Abstract class representing an expression. Subclasses must implement
|
|
22
|
-
* the exprName property and the accept method.
|
|
23
|
-
*/
|
|
24
|
-
export class Expression {
|
|
25
|
-
accept(visitor) {
|
|
26
|
-
if (this.exprName === "Operation") {
|
|
27
|
-
return visitor.visitOperation(this);
|
|
28
|
-
}
|
|
29
|
-
else if (this.exprName === "Comparison") {
|
|
30
|
-
return visitor.visitComparison(this);
|
|
31
|
-
}
|
|
32
|
-
else if (this.exprName === "StructuredQuery") {
|
|
33
|
-
return visitor.visitStructuredQuery(this);
|
|
34
|
-
}
|
|
35
|
-
else {
|
|
36
|
-
throw new Error("Unknown Expression type");
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Abstract class representing a filter directive. It extends the
|
|
42
|
-
* Expression class.
|
|
43
|
-
*/
|
|
44
|
-
export class FilterDirective extends Expression {
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Class representing a comparison filter directive. It extends the
|
|
48
|
-
* FilterDirective class.
|
|
49
|
-
*/
|
|
50
|
-
export class Comparison extends FilterDirective {
|
|
51
|
-
constructor(comparator, attribute, value) {
|
|
52
|
-
super();
|
|
53
|
-
Object.defineProperty(this, "comparator", {
|
|
54
|
-
enumerable: true,
|
|
55
|
-
configurable: true,
|
|
56
|
-
writable: true,
|
|
57
|
-
value: comparator
|
|
58
|
-
});
|
|
59
|
-
Object.defineProperty(this, "attribute", {
|
|
60
|
-
enumerable: true,
|
|
61
|
-
configurable: true,
|
|
62
|
-
writable: true,
|
|
63
|
-
value: attribute
|
|
64
|
-
});
|
|
65
|
-
Object.defineProperty(this, "value", {
|
|
66
|
-
enumerable: true,
|
|
67
|
-
configurable: true,
|
|
68
|
-
writable: true,
|
|
69
|
-
value: value
|
|
70
|
-
});
|
|
71
|
-
Object.defineProperty(this, "exprName", {
|
|
72
|
-
enumerable: true,
|
|
73
|
-
configurable: true,
|
|
74
|
-
writable: true,
|
|
75
|
-
value: "Comparison"
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* Class representing an operation filter directive. It extends the
|
|
81
|
-
* FilterDirective class.
|
|
82
|
-
*/
|
|
83
|
-
export class Operation extends FilterDirective {
|
|
84
|
-
constructor(operator, args) {
|
|
85
|
-
super();
|
|
86
|
-
Object.defineProperty(this, "operator", {
|
|
87
|
-
enumerable: true,
|
|
88
|
-
configurable: true,
|
|
89
|
-
writable: true,
|
|
90
|
-
value: operator
|
|
91
|
-
});
|
|
92
|
-
Object.defineProperty(this, "args", {
|
|
93
|
-
enumerable: true,
|
|
94
|
-
configurable: true,
|
|
95
|
-
writable: true,
|
|
96
|
-
value: args
|
|
97
|
-
});
|
|
98
|
-
Object.defineProperty(this, "exprName", {
|
|
99
|
-
enumerable: true,
|
|
100
|
-
configurable: true,
|
|
101
|
-
writable: true,
|
|
102
|
-
value: "Operation"
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
/**
|
|
107
|
-
* Class representing a structured query expression. It extends the
|
|
108
|
-
* Expression class.
|
|
109
|
-
*/
|
|
110
|
-
export class StructuredQuery extends Expression {
|
|
111
|
-
constructor(query, filter) {
|
|
112
|
-
super();
|
|
113
|
-
Object.defineProperty(this, "query", {
|
|
114
|
-
enumerable: true,
|
|
115
|
-
configurable: true,
|
|
116
|
-
writable: true,
|
|
117
|
-
value: query
|
|
118
|
-
});
|
|
119
|
-
Object.defineProperty(this, "filter", {
|
|
120
|
-
enumerable: true,
|
|
121
|
-
configurable: true,
|
|
122
|
-
writable: true,
|
|
123
|
-
value: filter
|
|
124
|
-
});
|
|
125
|
-
Object.defineProperty(this, "exprName", {
|
|
126
|
-
enumerable: true,
|
|
127
|
-
configurable: true,
|
|
128
|
-
writable: true,
|
|
129
|
-
value: "StructuredQuery"
|
|
130
|
-
});
|
|
131
|
-
}
|
|
132
|
-
}
|
|
1
|
+
export * from "@langchain/core/structured_query";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.DEFAULT_SUFFIX = exports.DEFAULT_PREFIX = exports.DEFAULT_SCHEMA = exports.EXAMPLE_PROMPT = exports.EXAMPLE_PROMPT_TEMPLATE = exports.DEFAULT_EXAMPLES = exports.NO_FILTER_ANSWER = exports.FULL_ANSWER = exports.SONG_DATA_SOURCE = void 0;
|
|
4
|
-
const
|
|
4
|
+
const index_js_1 = require("../../prompts/index.cjs");
|
|
5
5
|
exports.SONG_DATA_SOURCE = `\
|
|
6
6
|
\`\`\`json
|
|
7
7
|
{
|
|
@@ -65,7 +65,7 @@ User Query:
|
|
|
65
65
|
Structured Request:
|
|
66
66
|
{structured_request}
|
|
67
67
|
`;
|
|
68
|
-
exports.EXAMPLE_PROMPT = new
|
|
68
|
+
exports.EXAMPLE_PROMPT = new index_js_1.PromptTemplate({
|
|
69
69
|
inputVariables: ["i", "data_source", "user_query", "structured_request"],
|
|
70
70
|
template: exports.EXAMPLE_PROMPT_TEMPLATE,
|
|
71
71
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PromptTemplate } from "
|
|
1
|
+
import { PromptTemplate } from "../../prompts/index.js";
|
|
2
2
|
export declare const SONG_DATA_SOURCE: string;
|
|
3
3
|
export declare const FULL_ANSWER = "```json\n{{\n \"query\": \"teenager love\",\n \"filter\": \"and(or(eq(\\\"artist\\\", \\\"Taylor Swift\\\"), eq(\\\"artist\\\", \\\"Katy Perry\\\")), lt(\\\"length\\\", 180), eq(\\\"genre\\\", \\\"pop\\\"))\"\n}}";
|
|
4
4
|
export declare const NO_FILTER_ANSWER = "```json\n{{\n \"query\": \"\",\n \"filter\": \"NO_FILTER\"\n}}\n```";
|
|
@@ -4,28 +4,37 @@ exports.RetrievalQAChain = void 0;
|
|
|
4
4
|
const base_js_1 = require("./base.cjs");
|
|
5
5
|
const load_js_1 = require("./question_answering/load.cjs");
|
|
6
6
|
/**
|
|
7
|
+
* @deprecated This class will be removed in 0.3.0. See below for an example implementation using
|
|
8
|
+
* `createRetrievalChain`:
|
|
7
9
|
* Class representing a chain for performing question-answering tasks with
|
|
8
10
|
* a retrieval component.
|
|
9
11
|
* @example
|
|
10
12
|
* ```typescript
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
13
|
+
* import { createStuffDocumentsChain } from "langchain/chains/combine_documents";
|
|
14
|
+
* import { ChatPromptTemplate } from "@langchain/core/prompts";
|
|
15
|
+
* import { createRetrievalChain } from "langchain/chains/retrieval";
|
|
16
|
+
* import { MemoryVectorStore } from "langchain/vectorstores/memory";
|
|
17
|
+
*
|
|
18
|
+
* const documents = [...your documents here];
|
|
19
|
+
* const embeddings = ...your embeddings model;
|
|
20
|
+
* const llm = ...your LLM model;
|
|
19
21
|
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
+
* const vectorstore = await MemoryVectorStore.fromDocuments(
|
|
23
|
+
* documents,
|
|
24
|
+
* embeddings
|
|
25
|
+
* );
|
|
26
|
+
* const prompt = ChatPromptTemplate.fromTemplate(`Answer the user's question: {input}`);
|
|
22
27
|
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
28
|
+
* const combineDocsChain = await createStuffDocumentsChain({
|
|
29
|
+
* llm,
|
|
30
|
+
* prompt,
|
|
26
31
|
* });
|
|
27
|
-
*
|
|
32
|
+
* const retriever = vectorstore.asRetriever();
|
|
28
33
|
*
|
|
34
|
+
* const retrievalChain = await createRetrievalChain({
|
|
35
|
+
* combineDocsChain,
|
|
36
|
+
* retriever,
|
|
37
|
+
* });
|
|
29
38
|
* ```
|
|
30
39
|
*/
|
|
31
40
|
class RetrievalQAChain extends base_js_1.BaseChain {
|
|
@@ -16,28 +16,37 @@ export interface RetrievalQAChainInput extends Omit<ChainInputs, "memory"> {
|
|
|
16
16
|
returnSourceDocuments?: boolean;
|
|
17
17
|
}
|
|
18
18
|
/**
|
|
19
|
+
* @deprecated This class will be removed in 0.3.0. See below for an example implementation using
|
|
20
|
+
* `createRetrievalChain`:
|
|
19
21
|
* Class representing a chain for performing question-answering tasks with
|
|
20
22
|
* a retrieval component.
|
|
21
23
|
* @example
|
|
22
24
|
* ```typescript
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
25
|
+
* import { createStuffDocumentsChain } from "langchain/chains/combine_documents";
|
|
26
|
+
* import { ChatPromptTemplate } from "@langchain/core/prompts";
|
|
27
|
+
* import { createRetrievalChain } from "langchain/chains/retrieval";
|
|
28
|
+
* import { MemoryVectorStore } from "langchain/vectorstores/memory";
|
|
29
|
+
*
|
|
30
|
+
* const documents = [...your documents here];
|
|
31
|
+
* const embeddings = ...your embeddings model;
|
|
32
|
+
* const llm = ...your LLM model;
|
|
31
33
|
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
+
* const vectorstore = await MemoryVectorStore.fromDocuments(
|
|
35
|
+
* documents,
|
|
36
|
+
* embeddings
|
|
37
|
+
* );
|
|
38
|
+
* const prompt = ChatPromptTemplate.fromTemplate(`Answer the user's question: {input}`);
|
|
34
39
|
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
40
|
+
* const combineDocsChain = await createStuffDocumentsChain({
|
|
41
|
+
* llm,
|
|
42
|
+
* prompt,
|
|
38
43
|
* });
|
|
39
|
-
*
|
|
44
|
+
* const retriever = vectorstore.asRetriever();
|
|
40
45
|
*
|
|
46
|
+
* const retrievalChain = await createRetrievalChain({
|
|
47
|
+
* combineDocsChain,
|
|
48
|
+
* retriever,
|
|
49
|
+
* });
|
|
41
50
|
* ```
|
|
42
51
|
*/
|
|
43
52
|
export declare class RetrievalQAChain extends BaseChain implements RetrievalQAChainInput {
|
|
@@ -1,28 +1,37 @@
|
|
|
1
1
|
import { BaseChain } from "./base.js";
|
|
2
2
|
import { loadQAStuffChain, } from "./question_answering/load.js";
|
|
3
3
|
/**
|
|
4
|
+
* @deprecated This class will be removed in 0.3.0. See below for an example implementation using
|
|
5
|
+
* `createRetrievalChain`:
|
|
4
6
|
* Class representing a chain for performing question-answering tasks with
|
|
5
7
|
* a retrieval component.
|
|
6
8
|
* @example
|
|
7
9
|
* ```typescript
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
10
|
+
* import { createStuffDocumentsChain } from "langchain/chains/combine_documents";
|
|
11
|
+
* import { ChatPromptTemplate } from "@langchain/core/prompts";
|
|
12
|
+
* import { createRetrievalChain } from "langchain/chains/retrieval";
|
|
13
|
+
* import { MemoryVectorStore } from "langchain/vectorstores/memory";
|
|
14
|
+
*
|
|
15
|
+
* const documents = [...your documents here];
|
|
16
|
+
* const embeddings = ...your embeddings model;
|
|
17
|
+
* const llm = ...your LLM model;
|
|
16
18
|
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
+
* const vectorstore = await MemoryVectorStore.fromDocuments(
|
|
20
|
+
* documents,
|
|
21
|
+
* embeddings
|
|
22
|
+
* );
|
|
23
|
+
* const prompt = ChatPromptTemplate.fromTemplate(`Answer the user's question: {input}`);
|
|
19
24
|
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
25
|
+
* const combineDocsChain = await createStuffDocumentsChain({
|
|
26
|
+
* llm,
|
|
27
|
+
* prompt,
|
|
23
28
|
* });
|
|
24
|
-
*
|
|
29
|
+
* const retriever = vectorstore.asRetriever();
|
|
25
30
|
*
|
|
31
|
+
* const retrievalChain = await createRetrievalChain({
|
|
32
|
+
* combineDocsChain,
|
|
33
|
+
* retriever,
|
|
34
|
+
* });
|
|
26
35
|
* ```
|
|
27
36
|
*/
|
|
28
37
|
export class RetrievalQAChain extends BaseChain {
|
|
@@ -239,7 +239,7 @@ class UnstructuredLoader extends base_js_1.BaseDocumentLoader {
|
|
|
239
239
|
const documents = [];
|
|
240
240
|
for (const element of elements) {
|
|
241
241
|
const { metadata, text } = element;
|
|
242
|
-
if (typeof text === "string") {
|
|
242
|
+
if (typeof text === "string" && text !== "") {
|
|
243
243
|
documents.push(new documents_1.Document({
|
|
244
244
|
pageContent: text,
|
|
245
245
|
metadata: {
|
|
@@ -235,7 +235,7 @@ export class UnstructuredLoader extends BaseDocumentLoader {
|
|
|
235
235
|
const documents = [];
|
|
236
236
|
for (const element of elements) {
|
|
237
237
|
const { metadata, text } = element;
|
|
238
|
-
if (typeof text === "string") {
|
|
238
|
+
if (typeof text === "string" && text !== "") {
|
|
239
239
|
documents.push(new Document({
|
|
240
240
|
pageContent: text,
|
|
241
241
|
metadata: {
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.BrowserbaseLoader = void 0;
|
|
7
|
+
const documents_1 = require("@langchain/core/documents");
|
|
8
|
+
const sdk_1 = __importDefault(require("@browserbasehq/sdk"));
|
|
9
|
+
const base_js_1 = require("../base.cjs");
|
|
10
|
+
/**
|
|
11
|
+
* Load pre-rendered web pages using a headless browser hosted on Browserbase.
|
|
12
|
+
*
|
|
13
|
+
* Depends on `@browserbasehq/sdk` package.
|
|
14
|
+
* Get your API key from https://browserbase.com
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* import { BrowserbaseLoader } from "langchain/document_loaders/web/browserbase";
|
|
19
|
+
*
|
|
20
|
+
* const loader = new BrowserbaseLoader(["https://example.com"], {
|
|
21
|
+
* apiKey: process.env.BROWSERBASE_API_KEY,
|
|
22
|
+
* textContent: true,
|
|
23
|
+
* });
|
|
24
|
+
*
|
|
25
|
+
* const docs = await loader.load();
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* @param {string[]} urls - The URLs of the web pages to load.
|
|
29
|
+
* @param {BrowserbaseLoaderOptions} [options] - Browserbase client options.
|
|
30
|
+
*/
|
|
31
|
+
class BrowserbaseLoader extends base_js_1.BaseDocumentLoader {
|
|
32
|
+
constructor(urls, options = {}) {
|
|
33
|
+
super();
|
|
34
|
+
Object.defineProperty(this, "urls", {
|
|
35
|
+
enumerable: true,
|
|
36
|
+
configurable: true,
|
|
37
|
+
writable: true,
|
|
38
|
+
value: void 0
|
|
39
|
+
});
|
|
40
|
+
Object.defineProperty(this, "options", {
|
|
41
|
+
enumerable: true,
|
|
42
|
+
configurable: true,
|
|
43
|
+
writable: true,
|
|
44
|
+
value: void 0
|
|
45
|
+
});
|
|
46
|
+
Object.defineProperty(this, "browserbase", {
|
|
47
|
+
enumerable: true,
|
|
48
|
+
configurable: true,
|
|
49
|
+
writable: true,
|
|
50
|
+
value: void 0
|
|
51
|
+
});
|
|
52
|
+
this.urls = urls;
|
|
53
|
+
this.options = options;
|
|
54
|
+
this.browserbase = new sdk_1.default(options.apiKey);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Load pages from URLs.
|
|
58
|
+
*
|
|
59
|
+
* @returns {Promise<DocumentInterface[]>} - A promise which resolves to a list of documents.
|
|
60
|
+
*/
|
|
61
|
+
async load() {
|
|
62
|
+
const documents = [];
|
|
63
|
+
for await (const doc of this.lazyLoad()) {
|
|
64
|
+
documents.push(doc);
|
|
65
|
+
}
|
|
66
|
+
return documents;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Load pages from URLs.
|
|
70
|
+
*
|
|
71
|
+
* @returns {Generator<DocumentInterface>} - A generator that yields documents.
|
|
72
|
+
*/
|
|
73
|
+
async *lazyLoad() {
|
|
74
|
+
const pages = await this.browserbase.loadURLs(this.urls, this.options);
|
|
75
|
+
let index = 0;
|
|
76
|
+
for await (const page of pages) {
|
|
77
|
+
yield new documents_1.Document({
|
|
78
|
+
pageContent: page,
|
|
79
|
+
metadata: {
|
|
80
|
+
url: this.urls[index],
|
|
81
|
+
},
|
|
82
|
+
});
|
|
83
|
+
index += index + 1;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
exports.BrowserbaseLoader = BrowserbaseLoader;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { Document, type DocumentInterface } from "@langchain/core/documents";
|
|
2
|
+
import Browserbase, { BrowserbaseLoadOptions } from "@browserbasehq/sdk";
|
|
3
|
+
import { BaseDocumentLoader } from "../base.js";
|
|
4
|
+
import type { DocumentLoader } from "../base.js";
|
|
5
|
+
interface BrowserbaseLoaderOptions extends BrowserbaseLoadOptions {
|
|
6
|
+
apiKey?: string;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Load pre-rendered web pages using a headless browser hosted on Browserbase.
|
|
10
|
+
*
|
|
11
|
+
* Depends on `@browserbasehq/sdk` package.
|
|
12
|
+
* Get your API key from https://browserbase.com
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* import { BrowserbaseLoader } from "langchain/document_loaders/web/browserbase";
|
|
17
|
+
*
|
|
18
|
+
* const loader = new BrowserbaseLoader(["https://example.com"], {
|
|
19
|
+
* apiKey: process.env.BROWSERBASE_API_KEY,
|
|
20
|
+
* textContent: true,
|
|
21
|
+
* });
|
|
22
|
+
*
|
|
23
|
+
* const docs = await loader.load();
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
26
|
+
* @param {string[]} urls - The URLs of the web pages to load.
|
|
27
|
+
* @param {BrowserbaseLoaderOptions} [options] - Browserbase client options.
|
|
28
|
+
*/
|
|
29
|
+
export declare class BrowserbaseLoader extends BaseDocumentLoader implements DocumentLoader {
|
|
30
|
+
urls: string[];
|
|
31
|
+
options: BrowserbaseLoaderOptions;
|
|
32
|
+
browserbase: Browserbase;
|
|
33
|
+
constructor(urls: string[], options?: BrowserbaseLoaderOptions);
|
|
34
|
+
/**
|
|
35
|
+
* Load pages from URLs.
|
|
36
|
+
*
|
|
37
|
+
* @returns {Promise<DocumentInterface[]>} - A promise which resolves to a list of documents.
|
|
38
|
+
*/
|
|
39
|
+
load(): Promise<DocumentInterface[]>;
|
|
40
|
+
/**
|
|
41
|
+
* Load pages from URLs.
|
|
42
|
+
*
|
|
43
|
+
* @returns {Generator<DocumentInterface>} - A generator that yields documents.
|
|
44
|
+
*/
|
|
45
|
+
lazyLoad(): AsyncGenerator<Document<{
|
|
46
|
+
url: string;
|
|
47
|
+
}>, void, unknown>;
|
|
48
|
+
}
|
|
49
|
+
export {};
|