langchain 0.1.19-rc.1 → 0.1.19

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.
@@ -0,0 +1,88 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CouchbaseDocumentLoader = void 0;
4
+ const documents_1 = require("@langchain/core/documents");
5
+ const base_js_1 = require("../base.cjs");
6
+ /**
7
+ * loader for couchbase document
8
+ */
9
+ class CouchbaseDocumentLoader extends base_js_1.BaseDocumentLoader {
10
+ /**
11
+ * construct Couchbase document loader with a requirement for couchbase cluster client
12
+ * @param client { Cluster } [ couchbase connected client to connect to database ]
13
+ * @param query { string } [ query to get results from while loading the data ]
14
+ * @param pageContentFields { Array<string> } [ filters fields of the document and shows these only ]
15
+ * @param metadataFields { Array<string> } [ metadata fields required ]
16
+ */
17
+ constructor(client, query, pageContentFields, metadataFields) {
18
+ super();
19
+ Object.defineProperty(this, "cluster", {
20
+ enumerable: true,
21
+ configurable: true,
22
+ writable: true,
23
+ value: void 0
24
+ });
25
+ Object.defineProperty(this, "query", {
26
+ enumerable: true,
27
+ configurable: true,
28
+ writable: true,
29
+ value: void 0
30
+ });
31
+ Object.defineProperty(this, "pageContentFields", {
32
+ enumerable: true,
33
+ configurable: true,
34
+ writable: true,
35
+ value: void 0
36
+ });
37
+ Object.defineProperty(this, "metadataFields", {
38
+ enumerable: true,
39
+ configurable: true,
40
+ writable: true,
41
+ value: void 0
42
+ });
43
+ if (!client) {
44
+ throw new Error("Couchbase client cluster must be provided.");
45
+ }
46
+ this.cluster = client;
47
+ this.query = query;
48
+ this.pageContentFields = pageContentFields;
49
+ this.metadataFields = metadataFields;
50
+ }
51
+ /**
52
+ * Function to load document based on query from couchbase
53
+ * @returns {Promise<Document[]>} [ Returns a promise of all the documents as array ]
54
+ */
55
+ async load() {
56
+ const documents = [];
57
+ for await (const doc of this.lazyLoad()) {
58
+ documents.push(doc);
59
+ }
60
+ return documents;
61
+ }
62
+ /**
63
+ * Function to load documents based on iterator rather than full load
64
+ * @returns {AsyncIterable<Document>} [ Returns an iterator to fetch documents ]
65
+ */
66
+ async *lazyLoad() {
67
+ // Run SQL++ Query
68
+ const result = await this.cluster.query(this.query);
69
+ for await (const row of result.rows) {
70
+ let { metadataFields, pageContentFields } = this;
71
+ if (!pageContentFields) {
72
+ pageContentFields = Object.keys(row);
73
+ }
74
+ if (!metadataFields) {
75
+ metadataFields = [];
76
+ }
77
+ const metadata = metadataFields.reduce((obj, field) => ({ ...obj, [field]: row[field] }), {});
78
+ const document = pageContentFields
79
+ .map((k) => `${k}: ${JSON.stringify(row[k])}`)
80
+ .join("\n");
81
+ yield new documents_1.Document({
82
+ pageContent: document,
83
+ metadata,
84
+ });
85
+ }
86
+ }
87
+ }
88
+ exports.CouchbaseDocumentLoader = CouchbaseDocumentLoader;
@@ -0,0 +1,30 @@
1
+ import { Cluster } from "couchbase";
2
+ import { Document } from "@langchain/core/documents";
3
+ import { BaseDocumentLoader, DocumentLoader } from "../base.js";
4
+ /**
5
+ * loader for couchbase document
6
+ */
7
+ export declare class CouchbaseDocumentLoader extends BaseDocumentLoader implements DocumentLoader {
8
+ private cluster;
9
+ private query;
10
+ private pageContentFields?;
11
+ private metadataFields?;
12
+ /**
13
+ * construct Couchbase document loader with a requirement for couchbase cluster client
14
+ * @param client { Cluster } [ couchbase connected client to connect to database ]
15
+ * @param query { string } [ query to get results from while loading the data ]
16
+ * @param pageContentFields { Array<string> } [ filters fields of the document and shows these only ]
17
+ * @param metadataFields { Array<string> } [ metadata fields required ]
18
+ */
19
+ constructor(client: Cluster, query: string, pageContentFields?: string[], metadataFields?: string[]);
20
+ /**
21
+ * Function to load document based on query from couchbase
22
+ * @returns {Promise<Document[]>} [ Returns a promise of all the documents as array ]
23
+ */
24
+ load(): Promise<Document[]>;
25
+ /**
26
+ * Function to load documents based on iterator rather than full load
27
+ * @returns {AsyncIterable<Document>} [ Returns an iterator to fetch documents ]
28
+ */
29
+ lazyLoad(): AsyncIterable<Document>;
30
+ }
@@ -0,0 +1,84 @@
1
+ import { Document } from "@langchain/core/documents";
2
+ import { BaseDocumentLoader } from "../base.js";
3
+ /**
4
+ * loader for couchbase document
5
+ */
6
+ export class CouchbaseDocumentLoader extends BaseDocumentLoader {
7
+ /**
8
+ * construct Couchbase document loader with a requirement for couchbase cluster client
9
+ * @param client { Cluster } [ couchbase connected client to connect to database ]
10
+ * @param query { string } [ query to get results from while loading the data ]
11
+ * @param pageContentFields { Array<string> } [ filters fields of the document and shows these only ]
12
+ * @param metadataFields { Array<string> } [ metadata fields required ]
13
+ */
14
+ constructor(client, query, pageContentFields, metadataFields) {
15
+ super();
16
+ Object.defineProperty(this, "cluster", {
17
+ enumerable: true,
18
+ configurable: true,
19
+ writable: true,
20
+ value: void 0
21
+ });
22
+ Object.defineProperty(this, "query", {
23
+ enumerable: true,
24
+ configurable: true,
25
+ writable: true,
26
+ value: void 0
27
+ });
28
+ Object.defineProperty(this, "pageContentFields", {
29
+ enumerable: true,
30
+ configurable: true,
31
+ writable: true,
32
+ value: void 0
33
+ });
34
+ Object.defineProperty(this, "metadataFields", {
35
+ enumerable: true,
36
+ configurable: true,
37
+ writable: true,
38
+ value: void 0
39
+ });
40
+ if (!client) {
41
+ throw new Error("Couchbase client cluster must be provided.");
42
+ }
43
+ this.cluster = client;
44
+ this.query = query;
45
+ this.pageContentFields = pageContentFields;
46
+ this.metadataFields = metadataFields;
47
+ }
48
+ /**
49
+ * Function to load document based on query from couchbase
50
+ * @returns {Promise<Document[]>} [ Returns a promise of all the documents as array ]
51
+ */
52
+ async load() {
53
+ const documents = [];
54
+ for await (const doc of this.lazyLoad()) {
55
+ documents.push(doc);
56
+ }
57
+ return documents;
58
+ }
59
+ /**
60
+ * Function to load documents based on iterator rather than full load
61
+ * @returns {AsyncIterable<Document>} [ Returns an iterator to fetch documents ]
62
+ */
63
+ async *lazyLoad() {
64
+ // Run SQL++ Query
65
+ const result = await this.cluster.query(this.query);
66
+ for await (const row of result.rows) {
67
+ let { metadataFields, pageContentFields } = this;
68
+ if (!pageContentFields) {
69
+ pageContentFields = Object.keys(row);
70
+ }
71
+ if (!metadataFields) {
72
+ metadataFields = [];
73
+ }
74
+ const metadata = metadataFields.reduce((obj, field) => ({ ...obj, [field]: row[field] }), {});
75
+ const document = pageContentFields
76
+ .map((k) => `${k}: ${JSON.stringify(row[k])}`)
77
+ .join("\n");
78
+ yield new Document({
79
+ pageContent: document,
80
+ metadata,
81
+ });
82
+ }
83
+ }
84
+ }
@@ -102,6 +102,7 @@ exports.optionalImportEntrypoints = [
102
102
  "langchain/document_loaders/web/sitemap",
103
103
  "langchain/document_loaders/web/sonix_audio",
104
104
  "langchain/document_loaders/web/confluence",
105
+ "langchain/document_loaders/web/couchbase",
105
106
  "langchain/document_loaders/web/youtube",
106
107
  "langchain/document_loaders/fs/directory",
107
108
  "langchain/document_loaders/fs/buffer",
@@ -99,6 +99,7 @@ export const optionalImportEntrypoints = [
99
99
  "langchain/document_loaders/web/sitemap",
100
100
  "langchain/document_loaders/web/sonix_audio",
101
101
  "langchain/document_loaders/web/confluence",
102
+ "langchain/document_loaders/web/couchbase",
102
103
  "langchain/document_loaders/web/youtube",
103
104
  "langchain/document_loaders/fs/directory",
104
105
  "langchain/document_loaders/fs/buffer",
@@ -0,0 +1 @@
1
+ module.exports = require('../../dist/document_loaders/web/couchbase.cjs');
@@ -0,0 +1 @@
1
+ export * from '../../dist/document_loaders/web/couchbase.js'
@@ -0,0 +1 @@
1
+ export * from '../../dist/document_loaders/web/couchbase.js'
@@ -0,0 +1 @@
1
+ export * from '../../dist/document_loaders/web/couchbase.js'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "langchain",
3
- "version": "0.1.19-rc.1",
3
+ "version": "0.1.19",
4
4
  "description": "Typescript bindings for langchain",
5
5
  "type": "module",
6
6
  "engines": {
@@ -614,6 +614,10 @@
614
614
  "document_loaders/web/confluence.js",
615
615
  "document_loaders/web/confluence.d.ts",
616
616
  "document_loaders/web/confluence.d.cts",
617
+ "document_loaders/web/couchbase.cjs",
618
+ "document_loaders/web/couchbase.js",
619
+ "document_loaders/web/couchbase.d.ts",
620
+ "document_loaders/web/couchbase.d.cts",
617
621
  "document_loaders/web/searchapi.cjs",
618
622
  "document_loaders/web/searchapi.js",
619
623
  "document_loaders/web/searchapi.d.ts",
@@ -1247,6 +1251,7 @@
1247
1251
  "cheerio": "^1.0.0-rc.12",
1248
1252
  "chromadb": "^1.5.3",
1249
1253
  "convex": "^1.3.1",
1254
+ "couchbase": "^4.2.10",
1250
1255
  "d3-dsv": "^2.0.0",
1251
1256
  "dotenv": "^16.0.3",
1252
1257
  "dpdm": "^3.12.0",
@@ -1317,6 +1322,7 @@
1317
1322
  "cheerio": "^1.0.0-rc.12",
1318
1323
  "chromadb": "*",
1319
1324
  "convex": "^1.3.1",
1325
+ "couchbase": "^4.2.10",
1320
1326
  "d3-dsv": "^2.0.0",
1321
1327
  "epub2": "^3.0.1",
1322
1328
  "fast-xml-parser": "^4.2.7",
@@ -1411,6 +1417,9 @@
1411
1417
  "convex": {
1412
1418
  "optional": true
1413
1419
  },
1420
+ "couchbase": {
1421
+ "optional": true
1422
+ },
1414
1423
  "d3-dsv": {
1415
1424
  "optional": true
1416
1425
  },
@@ -1504,8 +1513,8 @@
1504
1513
  },
1505
1514
  "dependencies": {
1506
1515
  "@anthropic-ai/sdk": "^0.9.1",
1507
- "@langchain/community": "~0.0.28",
1508
- "@langchain/core": "~0.1.28",
1516
+ "@langchain/community": "~0.0.29",
1517
+ "@langchain/core": "~0.1.29",
1509
1518
  "@langchain/openai": "~0.0.14",
1510
1519
  "binary-extensions": "^2.2.0",
1511
1520
  "expr-eval": "^2.0.2",
@@ -2899,6 +2908,15 @@
2899
2908
  "import": "./document_loaders/web/confluence.js",
2900
2909
  "require": "./document_loaders/web/confluence.cjs"
2901
2910
  },
2911
+ "./document_loaders/web/couchbase": {
2912
+ "types": {
2913
+ "import": "./document_loaders/web/couchbase.d.ts",
2914
+ "require": "./document_loaders/web/couchbase.d.cts",
2915
+ "default": "./document_loaders/web/couchbase.d.ts"
2916
+ },
2917
+ "import": "./document_loaders/web/couchbase.js",
2918
+ "require": "./document_loaders/web/couchbase.cjs"
2919
+ },
2902
2920
  "./document_loaders/web/searchapi": {
2903
2921
  "types": {
2904
2922
  "import": "./document_loaders/web/searchapi.d.ts",