@langchain/google-cloud-sql-pg 0.0.2 → 1.0.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/CHANGELOG.md +26 -0
- package/LICENSE +6 -6
- package/README.md +1 -1
- package/dist/_virtual/rolldown_runtime.cjs +25 -0
- package/dist/chat_message_history.cjs +104 -137
- package/dist/chat_message_history.cjs.map +1 -0
- package/dist/chat_message_history.d.cts +57 -0
- package/dist/chat_message_history.d.ts +53 -43
- package/dist/chat_message_history.js +103 -133
- package/dist/chat_message_history.js.map +1 -0
- package/dist/engine.cjs +188 -242
- package/dist/engine.cjs.map +1 -0
- package/dist/engine.d.cts +138 -0
- package/dist/engine.d.ts +102 -80
- package/dist/engine.js +186 -234
- package/dist/engine.js.map +1 -0
- package/dist/index.cjs +21 -20
- package/dist/index.d.cts +6 -0
- package/dist/index.d.ts +6 -4
- package/dist/index.js +7 -4
- package/dist/indexes.cjs +96 -168
- package/dist/indexes.cjs.map +1 -0
- package/dist/indexes.d.cts +68 -0
- package/dist/indexes.d.ts +50 -47
- package/dist/indexes.js +90 -161
- package/dist/indexes.js.map +1 -0
- package/dist/loader.cjs +159 -242
- package/dist/loader.cjs.map +1 -0
- package/dist/loader.d.cts +101 -0
- package/dist/loader.d.ts +40 -26
- package/dist/loader.js +157 -237
- package/dist/loader.js.map +1 -0
- package/dist/utils/utils.cjs +36 -65
- package/dist/utils/utils.cjs.map +1 -0
- package/dist/utils/utils.js +36 -62
- package/dist/utils/utils.js.map +1 -0
- package/dist/vectorstore.cjs +438 -593
- package/dist/vectorstore.cjs.map +1 -0
- package/dist/vectorstore.d.cts +300 -0
- package/dist/vectorstore.d.ts +147 -130
- package/dist/vectorstore.js +436 -588
- package/dist/vectorstore.js.map +1 -0
- package/package.json +41 -48
- package/dist/utils/utils.d.ts +0 -22
- package/index.cjs +0 -1
- package/index.d.cts +0 -1
- package/index.d.ts +0 -1
- package/index.js +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"engine.js","names":["name: string","dataType: string","nullable: boolean","key: symbol","pool: knex.Knex","projectId: string","region: string","instance: string","database: string","dbUser: string","enableIAMAuth: boolean","dbConfig: knex.Knex.Config","engine: knex.Knex","url: string | knex.Knex.StaticConnectionConfig","poolConfig?: knex.Knex.PoolConfig","tableName: string","vectorSize: number","schemaName: string"],"sources":["../src/engine.ts"],"sourcesContent":["import {\n AuthTypes,\n Connector,\n IpAddressTypes,\n} from \"@google-cloud/cloud-sql-connector\";\nimport { GoogleAuth } from \"google-auth-library\";\nimport knex from \"knex\";\nimport { getIAMPrincipalEmail } from \"./utils/utils.js\";\n\nexport interface PostgresEngineArgs {\n ipType?: IpAddressTypes;\n user?: string;\n password?: string;\n iamAccountEmail?: string;\n}\n\nexport interface VectorStoreTableArgs {\n schemaName?: string;\n contentColumn?: string;\n embeddingColumn?: string;\n embeddingColumnType?: \"vector\" | \"halfvec\" | \"bit\" | \"sparsevec\";\n metadataColumns?: Column[];\n metadataJsonColumn?: string;\n idColumn?: string | Column;\n overwriteExisting?: boolean;\n storeMetadata?: boolean;\n}\n\nexport class Column {\n name: string;\n\n dataType: string;\n\n nullable: boolean;\n\n constructor(name: string, dataType: string, nullable: boolean = true) {\n this.name = name;\n this.dataType = dataType;\n this.nullable = nullable;\n\n this.postInitilization();\n }\n\n private postInitilization() {\n if (typeof this.name !== \"string\") {\n throw Error(\"Column name must be type string\");\n }\n\n if (typeof this.dataType !== \"string\") {\n throw Error(\"Column data_type must be type string\");\n }\n }\n}\n\nconst USER_AGENT = \"langchain-google-cloud-sql-pg-js\";\n\n/**\n * Cloud SQL shared connection pool\n *\n * Setup:\n * Install `@langchain/google-cloud-sql-pg`\n *\n * <details open>\n * <summary><strong>Instantiate</strong></summary>\n *\n * ```typescript\n * import { Column, PostgresEngine, PostgresEngineArgs } from \"@langchain/google-cloud-sql-pg\";\n *\n * const pgArgs: PostgresEngineArgs = {\n * user: \"db-user\",\n * password: \"password\"\n *}\n *\n * const engine: PostgresEngine = await PostgresEngine.fromInstance(\n * \"project-id\",\n * \"region\",\n * \"instance-name\",\n * \"database-name\",\n * pgArgs\n * );\n * ```\n * </details>\n *\n * <br />\n *\n */\nexport class PostgresEngine {\n private static _createKey = Symbol(\"key\");\n\n pool: knex.Knex;\n\n static connector: Connector;\n\n constructor(key: symbol, pool: knex.Knex) {\n if (key !== PostgresEngine._createKey) {\n throw Error(\"Only create class through 'create' method!\");\n }\n this.pool = pool;\n }\n\n /**\n * @param projectId Required - GCP Project ID\n * @param region Required - Postgres Instance Region\n * @param instance Required - Postgres Instance name\n * @param database Required - Database name\n * @param ipType Optional - IP address type. Defaults to IPAddressType.PUBLIC\n * @param user Optional - Postgres user name. Defaults to undefined\n * @param password Optional - Postgres user password. Defaults to undefined\n * @param iamAccountEmail Optional - IAM service account email. Defaults to undefined\n * @returns PostgresEngine instance\n */\n\n static async fromInstance(\n projectId: string,\n region: string,\n instance: string,\n database: string,\n {\n ipType = IpAddressTypes.PUBLIC,\n user,\n password,\n iamAccountEmail,\n }: PostgresEngineArgs = {}\n ): Promise<PostgresEngine> {\n let dbUser: string;\n let enableIAMAuth: boolean;\n\n if ((!user && password) || (user && !password)) {\n // XOR for strings\n throw Error(\n \"Only one of 'user' or 'password' were specified. Either \" +\n \"both should be specified to use basic user/password \" +\n \"authentication or neither for IAM DB authentication.\"\n );\n }\n\n // User and password are given so we use the basic auth\n if (user !== undefined && password !== undefined) {\n enableIAMAuth = false;\n dbUser = user!;\n } else {\n enableIAMAuth = true;\n if (iamAccountEmail !== undefined) {\n dbUser = iamAccountEmail;\n } else {\n // Get application default credentials\n const auth = new GoogleAuth({\n scopes: \"https://www.googleapis.com/auth/cloud-platform\",\n });\n // dbUser should be the iam principal email by passing the credentials obtained\n dbUser = await getIAMPrincipalEmail(auth);\n }\n }\n\n PostgresEngine.connector = new Connector({ userAgent: USER_AGENT });\n const clientOpts = await PostgresEngine.connector.getOptions({\n instanceConnectionName: `${projectId}:${region}:${instance}`,\n ipType,\n authType: enableIAMAuth ? AuthTypes.IAM : AuthTypes.PASSWORD,\n });\n\n const dbConfig: knex.Knex.Config = {\n client: \"pg\",\n connection: {\n ...clientOpts,\n ...(password ? { password } : {}),\n user: dbUser,\n database,\n },\n };\n\n const engine = knex(dbConfig);\n\n return new PostgresEngine(PostgresEngine._createKey, engine);\n }\n\n /**\n * Create a PostgresEngine instance from an Knex instance.\n *\n * @param engine knex instance\n * @returns PostgresEngine instance from a knex instance\n */\n static async fromPool(engine: knex.Knex) {\n return new PostgresEngine(PostgresEngine._createKey, engine);\n }\n\n /**\n * Create a PostgresEngine instance from arguments.\n *\n * @param url URL use to connect to a database\n * @param poolConfig Optional - Configuration pool to use in the Knex configuration\n * @returns PostgresEngine instance\n */\n static async fromConnectionString(\n url: string | knex.Knex.StaticConnectionConfig,\n poolConfig?: knex.Knex.PoolConfig\n ) {\n const driver = \"postgresql+asyncpg\";\n\n if (typeof url === \"string\" && !url.startsWith(driver)) {\n throw Error(\"Driver must be type 'postgresql+asyncpg'\");\n }\n\n const dbConfig: knex.Knex.Config = {\n client: \"pg\",\n connection: url,\n acquireConnectionTimeout: 1000000,\n pool: {\n ...poolConfig,\n acquireTimeoutMillis: 600000,\n },\n };\n\n const engine = knex(dbConfig);\n\n return new PostgresEngine(PostgresEngine._createKey, engine);\n }\n\n /**\n * Create a table for saving of vectors to be used with PostgresVectorStore.\n *\n * @param tableName Postgres database table name. Parameter is not escaped. Do not use with end user input.\n * @param vectorSize Vector size for the embedding model to be used.\n * @param schemaName The schema name to store Postgres database table. Default: \"public\". Parameter is not escaped. Do not use with end user input.\n * @param contentColumn Name of the column to store document content. Default: \"content\".\n * @param embeddingColumn Name of the column to store vector embeddings. Default: \"embedding\".\n * @param embeddingColumnType Type of the embedding column (\"vector\" | \"halfvec\" | \"bit\" | \"sparsevec\"). Default: \"vector\". More info on HNSW-supported types: https://github.com/pgvector/pgvector#hnsw\n * @param metadataColumns Optional - A list of Columns to create for custom metadata. Default: [].\n * @param metadataJsonColumn Optional - The column to store extra metadata in JSON format. Default: \"langchain_metadata\".\n * @param idColumn Optional - Column to store ids. Default: \"langchain_id\" column name with data type UUID.\n * @param overwriteExisting Whether to drop existing table. Default: False.\n * @param storeMetadata Whether to store metadata in the table. Default: True.\n */\n async initVectorstoreTable(\n tableName: string,\n vectorSize: number,\n {\n schemaName = \"public\",\n contentColumn = \"content\",\n embeddingColumn = \"embedding\",\n embeddingColumnType = \"vector\",\n metadataColumns = [],\n metadataJsonColumn = \"langchain_metadata\",\n idColumn = \"langchain_id\",\n overwriteExisting = false,\n storeMetadata = true,\n }: VectorStoreTableArgs = {}\n ): Promise<void> {\n await this.pool.raw(\"CREATE EXTENSION IF NOT EXISTS vector\");\n\n if (overwriteExisting) {\n await this.pool.schema\n .withSchema(schemaName)\n .dropTableIfExists(tableName);\n }\n\n const idDataType =\n typeof idColumn === \"string\" ? \"UUID\" : idColumn.dataType;\n const idColumnName =\n typeof idColumn === \"string\" ? idColumn : idColumn.name;\n\n let query = `CREATE TABLE ${schemaName}.${tableName}(\n ${idColumnName} ${idDataType} PRIMARY KEY,\n ${contentColumn} TEXT NOT NULL,\n ${embeddingColumn} ${embeddingColumnType}(${vectorSize}) NOT NULL`;\n\n for (const column of metadataColumns) {\n const nullable = !column.nullable ? \"NOT NULL\" : \"\";\n query += `,\\n ${column.name} ${column.dataType} ${nullable}`;\n }\n\n if (storeMetadata) {\n query += `,\\n${metadataJsonColumn} JSON`;\n }\n\n query += `\\n);`;\n\n await this.pool.raw(query);\n }\n\n /**\n * Create a Cloud SQL table to store chat history.\n *\n * @param tableName Table name to store chat history\n * @param schemaName Schema name to store chat history table\n */\n\n async initChatHistoryTable(\n tableName: string,\n schemaName: string = \"public\"\n ): Promise<void> {\n await this.pool.raw(\n `CREATE TABLE IF NOT EXISTS ${schemaName}.${tableName}(\n id SERIAL PRIMARY KEY,\n session_id TEXT NOT NULL,\n data JSONB NOT NULL,\n type TEXT NOT NULL);`\n );\n }\n\n /**\n * Dispose of connection pool\n */\n async closeConnection(): Promise<void> {\n await this.pool.destroy();\n if (PostgresEngine.connector !== undefined) {\n PostgresEngine.connector.close();\n }\n }\n\n // Just to test the connection to the database\n testConnection() {\n const now = this.pool.raw(\"SELECT NOW() as currentTimestamp\");\n return now;\n }\n}\n\nexport default PostgresEngine;\n"],"mappings":"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"}
|
package/dist/index.cjs
CHANGED
|
@@ -1,20 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
1
|
+
const require_engine = require('./engine.cjs');
|
|
2
|
+
const require_chat_message_history = require('./chat_message_history.cjs');
|
|
3
|
+
const require_indexes = require('./indexes.cjs');
|
|
4
|
+
const require_vectorstore = require('./vectorstore.cjs');
|
|
5
|
+
const require_loader = require('./loader.cjs');
|
|
6
|
+
|
|
7
|
+
exports.BaseIndex = require_indexes.BaseIndex;
|
|
8
|
+
exports.Column = require_engine.Column;
|
|
9
|
+
exports.DEFAULT_DISTANCE_STRATEGY = require_indexes.DEFAULT_DISTANCE_STRATEGY;
|
|
10
|
+
exports.DEFAULT_INDEX_NAME_SUFFIX = require_indexes.DEFAULT_INDEX_NAME_SUFFIX;
|
|
11
|
+
exports.DistanceStrategy = require_indexes.DistanceStrategy;
|
|
12
|
+
exports.ExactNearestNeighbor = require_indexes.ExactNearestNeighbor;
|
|
13
|
+
exports.HNSWIndex = require_indexes.HNSWIndex;
|
|
14
|
+
exports.HNSWQueryOptions = require_indexes.HNSWQueryOptions;
|
|
15
|
+
exports.IVFFlatIndex = require_indexes.IVFFlatIndex;
|
|
16
|
+
exports.IVFFlatQueryOptions = require_indexes.IVFFlatQueryOptions;
|
|
17
|
+
exports.PostgresChatMessageHistory = require_chat_message_history.PostgresChatMessageHistory;
|
|
18
|
+
exports.PostgresEngine = require_engine.PostgresEngine;
|
|
19
|
+
exports.PostgresLoader = require_loader.PostgresLoader;
|
|
20
|
+
exports.PostgresVectorStore = require_vectorstore.PostgresVectorStore;
|
|
21
|
+
exports.QueryOptions = require_indexes.QueryOptions;
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Column, PostgresEngine, PostgresEngineArgs, VectorStoreTableArgs } from "./engine.cjs";
|
|
2
|
+
import { PostgresChatMessageHistory, PostgresChatMessageHistoryInput } from "./chat_message_history.cjs";
|
|
3
|
+
import { BaseIndex, BaseIndexArgs, DEFAULT_DISTANCE_STRATEGY, DEFAULT_INDEX_NAME_SUFFIX, DistanceStrategy, ExactNearestNeighbor, HNSWIndex, HNSWQueryOptions, IVFFlatIndex, IVFFlatQueryOptions, QueryOptions } from "./indexes.cjs";
|
|
4
|
+
import { PostgresVectorStore, PostgresVectorStoreArgs, dbConfigArgs } from "./vectorstore.cjs";
|
|
5
|
+
import { PostgresLoader, PostgresLoaderOptions } from "./loader.cjs";
|
|
6
|
+
export { BaseIndex, BaseIndexArgs, Column, DEFAULT_DISTANCE_STRATEGY, DEFAULT_INDEX_NAME_SUFFIX, DistanceStrategy, ExactNearestNeighbor, HNSWIndex, HNSWQueryOptions, IVFFlatIndex, IVFFlatQueryOptions, PostgresChatMessageHistory, PostgresChatMessageHistoryInput, PostgresEngine, PostgresEngineArgs, PostgresLoader, PostgresLoaderOptions, PostgresVectorStore, PostgresVectorStoreArgs, QueryOptions, VectorStoreTableArgs, dbConfigArgs };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { Column, PostgresEngine, PostgresEngineArgs, VectorStoreTableArgs } from "./engine.js";
|
|
2
|
+
import { PostgresChatMessageHistory, PostgresChatMessageHistoryInput } from "./chat_message_history.js";
|
|
3
|
+
import { BaseIndex, BaseIndexArgs, DEFAULT_DISTANCE_STRATEGY, DEFAULT_INDEX_NAME_SUFFIX, DistanceStrategy, ExactNearestNeighbor, HNSWIndex, HNSWQueryOptions, IVFFlatIndex, IVFFlatQueryOptions, QueryOptions } from "./indexes.js";
|
|
4
|
+
import { PostgresVectorStore, PostgresVectorStoreArgs, dbConfigArgs } from "./vectorstore.js";
|
|
5
|
+
import { PostgresLoader, PostgresLoaderOptions } from "./loader.js";
|
|
6
|
+
export { BaseIndex, BaseIndexArgs, Column, DEFAULT_DISTANCE_STRATEGY, DEFAULT_INDEX_NAME_SUFFIX, DistanceStrategy, ExactNearestNeighbor, HNSWIndex, HNSWQueryOptions, IVFFlatIndex, IVFFlatQueryOptions, PostgresChatMessageHistory, PostgresChatMessageHistoryInput, PostgresEngine, PostgresEngineArgs, PostgresLoader, PostgresLoaderOptions, PostgresVectorStore, PostgresVectorStoreArgs, QueryOptions, VectorStoreTableArgs, dbConfigArgs };
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { Column, PostgresEngine } from "./engine.js";
|
|
2
|
+
import { PostgresChatMessageHistory } from "./chat_message_history.js";
|
|
3
|
+
import { BaseIndex, DEFAULT_DISTANCE_STRATEGY, DEFAULT_INDEX_NAME_SUFFIX, DistanceStrategy, ExactNearestNeighbor, HNSWIndex, HNSWQueryOptions, IVFFlatIndex, IVFFlatQueryOptions, QueryOptions } from "./indexes.js";
|
|
4
|
+
import { PostgresVectorStore } from "./vectorstore.js";
|
|
5
|
+
import { PostgresLoader } from "./loader.js";
|
|
6
|
+
|
|
7
|
+
export { BaseIndex, Column, DEFAULT_DISTANCE_STRATEGY, DEFAULT_INDEX_NAME_SUFFIX, DistanceStrategy, ExactNearestNeighbor, HNSWIndex, HNSWQueryOptions, IVFFlatIndex, IVFFlatQueryOptions, PostgresChatMessageHistory, PostgresEngine, PostgresLoader, PostgresVectorStore, QueryOptions };
|
package/dist/indexes.cjs
CHANGED
|
@@ -1,174 +1,102 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
enumerable: true,
|
|
14
|
-
configurable: true,
|
|
15
|
-
writable: true,
|
|
16
|
-
value: void 0
|
|
17
|
-
});
|
|
18
|
-
Object.defineProperty(this, "indexFunction", {
|
|
19
|
-
enumerable: true,
|
|
20
|
-
configurable: true,
|
|
21
|
-
writable: true,
|
|
22
|
-
value: void 0
|
|
23
|
-
});
|
|
24
|
-
this.operator = operator;
|
|
25
|
-
this.searchFunction = searchFunction;
|
|
26
|
-
this.indexFunction = indexFunction;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
1
|
+
|
|
2
|
+
//#region src/indexes.ts
|
|
3
|
+
var StrategyMixin = class {
|
|
4
|
+
operator;
|
|
5
|
+
searchFunction;
|
|
6
|
+
indexFunction;
|
|
7
|
+
constructor(operator, searchFunction, indexFunction) {
|
|
8
|
+
this.operator = operator;
|
|
9
|
+
this.searchFunction = searchFunction;
|
|
10
|
+
this.indexFunction = indexFunction;
|
|
11
|
+
}
|
|
12
|
+
};
|
|
29
13
|
/**
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
14
|
+
* Enumerator of the Distance strategies.
|
|
15
|
+
*/
|
|
16
|
+
var DistanceStrategy = class extends StrategyMixin {
|
|
17
|
+
static EUCLIDEAN = new StrategyMixin("<->", "l2_distance", "vector_l2_ops");
|
|
18
|
+
static COSINE_DISTANCE = new StrategyMixin("<=>", "cosine_distance", "vector_cosine_ops");
|
|
19
|
+
static INNER_PRODUCT = new StrategyMixin("<#>", "inner_product", "vector_ip_ops");
|
|
20
|
+
};
|
|
21
|
+
const DEFAULT_DISTANCE_STRATEGY = DistanceStrategy.COSINE_DISTANCE;
|
|
22
|
+
const DEFAULT_INDEX_NAME_SUFFIX = "langchainvectorindex";
|
|
23
|
+
var BaseIndex = class {
|
|
24
|
+
name;
|
|
25
|
+
indexType;
|
|
26
|
+
distanceStrategy;
|
|
27
|
+
partialIndexes;
|
|
28
|
+
constructor(name, indexType = "base", distanceStrategy = DistanceStrategy.COSINE_DISTANCE, partialIndexes = []) {
|
|
29
|
+
this.name = name;
|
|
30
|
+
this.indexType = indexType;
|
|
31
|
+
this.distanceStrategy = distanceStrategy;
|
|
32
|
+
this.partialIndexes = partialIndexes;
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
var ExactNearestNeighbor = class extends BaseIndex {
|
|
36
|
+
constructor(baseArgs) {
|
|
37
|
+
super(baseArgs?.name, "exactnearestneighbor", baseArgs?.distanceStrategy, baseArgs?.partialIndexes);
|
|
38
|
+
}
|
|
39
|
+
indexOptions() {
|
|
40
|
+
throw new Error("indexOptions method must be implemented by subclass");
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
var HNSWIndex = class extends BaseIndex {
|
|
44
|
+
m;
|
|
45
|
+
efConstruction;
|
|
46
|
+
constructor(baseArgs, m, efConstruction) {
|
|
47
|
+
super(baseArgs?.name, "hnsw", baseArgs?.distanceStrategy, baseArgs?.partialIndexes);
|
|
48
|
+
this.m = m ?? 16;
|
|
49
|
+
this.efConstruction = efConstruction ?? 64;
|
|
50
|
+
}
|
|
51
|
+
indexOptions() {
|
|
52
|
+
return `(m = ${this.m}, ef_construction = ${this.efConstruction})`;
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
var IVFFlatIndex = class extends BaseIndex {
|
|
56
|
+
lists;
|
|
57
|
+
constructor(baseArgs, lists) {
|
|
58
|
+
super(baseArgs?.name, "ivfflat", baseArgs?.distanceStrategy, baseArgs?.partialIndexes);
|
|
59
|
+
this.lists = lists ?? 100;
|
|
60
|
+
}
|
|
61
|
+
indexOptions() {
|
|
62
|
+
return `(lists = ${this.lists})`;
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* Convert index attributes to string.
|
|
67
|
+
* Must be implemented by subclasses.
|
|
68
|
+
*/
|
|
69
|
+
var QueryOptions = class {};
|
|
70
|
+
var HNSWQueryOptions = class extends QueryOptions {
|
|
71
|
+
efSearch;
|
|
72
|
+
constructor(efSearch) {
|
|
73
|
+
super();
|
|
74
|
+
this.efSearch = efSearch ?? 40;
|
|
75
|
+
}
|
|
76
|
+
to_string() {
|
|
77
|
+
return `hnsw.ef_search = ${this.efSearch}`;
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
var IVFFlatQueryOptions = class extends QueryOptions {
|
|
81
|
+
probes;
|
|
82
|
+
constructor(probes) {
|
|
83
|
+
super();
|
|
84
|
+
this.probes = probes ?? 1;
|
|
85
|
+
}
|
|
86
|
+
to_string() {
|
|
87
|
+
return `ivflfat.probes = ${this.probes}`;
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
//#endregion
|
|
87
92
|
exports.BaseIndex = BaseIndex;
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
}
|
|
92
|
-
indexOptions() {
|
|
93
|
-
throw new Error("indexOptions method must be implemented by subclass");
|
|
94
|
-
}
|
|
95
|
-
}
|
|
93
|
+
exports.DEFAULT_DISTANCE_STRATEGY = DEFAULT_DISTANCE_STRATEGY;
|
|
94
|
+
exports.DEFAULT_INDEX_NAME_SUFFIX = DEFAULT_INDEX_NAME_SUFFIX;
|
|
95
|
+
exports.DistanceStrategy = DistanceStrategy;
|
|
96
96
|
exports.ExactNearestNeighbor = ExactNearestNeighbor;
|
|
97
|
-
class HNSWIndex extends BaseIndex {
|
|
98
|
-
constructor(baseArgs, m, efConstruction) {
|
|
99
|
-
super(baseArgs?.name, "hnsw", baseArgs?.distanceStrategy, baseArgs?.partialIndexes);
|
|
100
|
-
Object.defineProperty(this, "m", {
|
|
101
|
-
enumerable: true,
|
|
102
|
-
configurable: true,
|
|
103
|
-
writable: true,
|
|
104
|
-
value: void 0
|
|
105
|
-
});
|
|
106
|
-
Object.defineProperty(this, "efConstruction", {
|
|
107
|
-
enumerable: true,
|
|
108
|
-
configurable: true,
|
|
109
|
-
writable: true,
|
|
110
|
-
value: void 0
|
|
111
|
-
});
|
|
112
|
-
this.m = m ?? 16;
|
|
113
|
-
this.efConstruction = efConstruction ?? 64;
|
|
114
|
-
}
|
|
115
|
-
indexOptions() {
|
|
116
|
-
return `(m = ${this.m}, ef_construction = ${this.efConstruction})`;
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
97
|
exports.HNSWIndex = HNSWIndex;
|
|
120
|
-
class IVFFlatIndex extends BaseIndex {
|
|
121
|
-
constructor(baseArgs, lists) {
|
|
122
|
-
super(baseArgs?.name, "ivfflat", baseArgs?.distanceStrategy, baseArgs?.partialIndexes);
|
|
123
|
-
Object.defineProperty(this, "lists", {
|
|
124
|
-
enumerable: true,
|
|
125
|
-
configurable: true,
|
|
126
|
-
writable: true,
|
|
127
|
-
value: void 0
|
|
128
|
-
});
|
|
129
|
-
this.lists = lists ?? 100;
|
|
130
|
-
}
|
|
131
|
-
indexOptions() {
|
|
132
|
-
return `(lists = ${this.lists})`;
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
exports.IVFFlatIndex = IVFFlatIndex;
|
|
136
|
-
/**
|
|
137
|
-
* Convert index attributes to string.
|
|
138
|
-
* Must be implemented by subclasses.
|
|
139
|
-
*/
|
|
140
|
-
class QueryOptions {
|
|
141
|
-
}
|
|
142
|
-
exports.QueryOptions = QueryOptions;
|
|
143
|
-
class HNSWQueryOptions extends QueryOptions {
|
|
144
|
-
constructor(efSearch) {
|
|
145
|
-
super();
|
|
146
|
-
Object.defineProperty(this, "efSearch", {
|
|
147
|
-
enumerable: true,
|
|
148
|
-
configurable: true,
|
|
149
|
-
writable: true,
|
|
150
|
-
value: void 0
|
|
151
|
-
});
|
|
152
|
-
this.efSearch = efSearch ?? 40;
|
|
153
|
-
}
|
|
154
|
-
to_string() {
|
|
155
|
-
return `hnsw.ef_search = ${this.efSearch}`;
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
98
|
exports.HNSWQueryOptions = HNSWQueryOptions;
|
|
159
|
-
|
|
160
|
-
constructor(probes) {
|
|
161
|
-
super();
|
|
162
|
-
Object.defineProperty(this, "probes", {
|
|
163
|
-
enumerable: true,
|
|
164
|
-
configurable: true,
|
|
165
|
-
writable: true,
|
|
166
|
-
value: void 0
|
|
167
|
-
});
|
|
168
|
-
this.probes = probes ?? 1;
|
|
169
|
-
}
|
|
170
|
-
to_string() {
|
|
171
|
-
return `ivflfat.probes = ${this.probes}`;
|
|
172
|
-
}
|
|
173
|
-
}
|
|
99
|
+
exports.IVFFlatIndex = IVFFlatIndex;
|
|
174
100
|
exports.IVFFlatQueryOptions = IVFFlatQueryOptions;
|
|
101
|
+
exports.QueryOptions = QueryOptions;
|
|
102
|
+
//# sourceMappingURL=indexes.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"indexes.cjs","names":["operator: string","searchFunction: string","indexFunction: string","DEFAULT_INDEX_NAME_SUFFIX: string","name?: string","indexType: string","distanceStrategy: DistanceStrategy","partialIndexes: string[]","baseArgs?: BaseIndexArgs","m?: number","efConstruction?: number","baseArgs: BaseIndexArgs","lists?: number","efSearch?: number","probes?: number"],"sources":["../src/indexes.ts"],"sourcesContent":["class StrategyMixin {\n operator: string;\n\n searchFunction: string;\n\n indexFunction: string;\n\n constructor(operator: string, searchFunction: string, indexFunction: string) {\n this.operator = operator;\n this.searchFunction = searchFunction;\n this.indexFunction = indexFunction;\n }\n}\n\n/**\n * Enumerator of the Distance strategies.\n */\nexport class DistanceStrategy extends StrategyMixin {\n public static EUCLIDEAN = new StrategyMixin(\n \"<->\",\n \"l2_distance\",\n \"vector_l2_ops\"\n );\n\n public static COSINE_DISTANCE = new StrategyMixin(\n \"<=>\",\n \"cosine_distance\",\n \"vector_cosine_ops\"\n );\n\n public static INNER_PRODUCT = new StrategyMixin(\n \"<#>\",\n \"inner_product\",\n \"vector_ip_ops\"\n );\n}\n\nexport const DEFAULT_DISTANCE_STRATEGY = DistanceStrategy.COSINE_DISTANCE;\nexport const DEFAULT_INDEX_NAME_SUFFIX: string = \"langchainvectorindex\";\n\nexport interface BaseIndexArgs {\n name?: string;\n distanceStrategy?: DistanceStrategy;\n partialIndexes?: string[];\n}\n\nexport abstract class BaseIndex {\n name?: string;\n\n indexType: string;\n\n distanceStrategy: DistanceStrategy;\n\n partialIndexes?: string[];\n\n constructor(\n name?: string,\n indexType: string = \"base\",\n distanceStrategy: DistanceStrategy = DistanceStrategy.COSINE_DISTANCE,\n partialIndexes: string[] = []\n ) {\n this.name = name;\n this.indexType = indexType;\n this.distanceStrategy = distanceStrategy;\n this.partialIndexes = partialIndexes;\n }\n\n /**\n * Set index query options for vector store initialization.\n */\n abstract indexOptions(): string;\n}\n\nexport class ExactNearestNeighbor extends BaseIndex {\n constructor(baseArgs?: BaseIndexArgs) {\n super(\n baseArgs?.name,\n \"exactnearestneighbor\",\n baseArgs?.distanceStrategy,\n baseArgs?.partialIndexes\n );\n }\n\n indexOptions(): string {\n throw new Error(\"indexOptions method must be implemented by subclass\");\n }\n}\n\nexport class HNSWIndex extends BaseIndex {\n m: number;\n\n efConstruction: number;\n\n constructor(baseArgs?: BaseIndexArgs, m?: number, efConstruction?: number) {\n super(\n baseArgs?.name,\n \"hnsw\",\n baseArgs?.distanceStrategy,\n baseArgs?.partialIndexes\n );\n this.m = m ?? 16;\n this.efConstruction = efConstruction ?? 64;\n }\n\n indexOptions(): string {\n return `(m = ${this.m}, ef_construction = ${this.efConstruction})`;\n }\n}\n\nexport class IVFFlatIndex extends BaseIndex {\n lists: number;\n\n constructor(baseArgs: BaseIndexArgs, lists?: number) {\n super(\n baseArgs?.name,\n \"ivfflat\",\n baseArgs?.distanceStrategy,\n baseArgs?.partialIndexes\n );\n this.lists = lists ?? 100;\n }\n\n indexOptions(): string {\n return `(lists = ${this.lists})`;\n }\n}\n\n/**\n * Convert index attributes to string.\n * Must be implemented by subclasses.\n */\nexport abstract class QueryOptions {\n abstract to_string(): string;\n}\n\nexport class HNSWQueryOptions extends QueryOptions {\n efSearch: number;\n\n constructor(efSearch?: number) {\n super();\n this.efSearch = efSearch ?? 40;\n }\n\n to_string(): string {\n return `hnsw.ef_search = ${this.efSearch}`;\n }\n}\n\nexport class IVFFlatQueryOptions extends QueryOptions {\n readonly probes: number;\n\n constructor(probes?: number) {\n super();\n this.probes = probes ?? 1;\n }\n\n to_string(): string {\n return `ivflfat.probes = ${this.probes}`;\n }\n}\n"],"mappings":";;AAAA,IAAM,gBAAN,MAAoB;CAClB;CAEA;CAEA;CAEA,YAAYA,UAAkBC,gBAAwBC,eAAuB;EAC3E,KAAK,WAAW;EAChB,KAAK,iBAAiB;EACtB,KAAK,gBAAgB;CACtB;AACF;;;;AAKD,IAAa,mBAAb,cAAsC,cAAc;CAClD,OAAc,YAAY,IAAI,cAC5B,OACA,eACA;CAGF,OAAc,kBAAkB,IAAI,cAClC,OACA,mBACA;CAGF,OAAc,gBAAgB,IAAI,cAChC,OACA,iBACA;AAEH;AAED,MAAa,4BAA4B,iBAAiB;AAC1D,MAAaC,4BAAoC;AAQjD,IAAsB,YAAtB,MAAgC;CAC9B;CAEA;CAEA;CAEA;CAEA,YACEC,MACAC,YAAoB,QACpBC,mBAAqC,iBAAiB,iBACtDC,iBAA2B,CAAE,GAC7B;EACA,KAAK,OAAO;EACZ,KAAK,YAAY;EACjB,KAAK,mBAAmB;EACxB,KAAK,iBAAiB;CACvB;AAMF;AAED,IAAa,uBAAb,cAA0C,UAAU;CAClD,YAAYC,UAA0B;EACpC,MACE,UAAU,MACV,wBACA,UAAU,kBACV,UAAU,eACX;CACF;CAED,eAAuB;AACrB,QAAM,IAAI,MAAM;CACjB;AACF;AAED,IAAa,YAAb,cAA+B,UAAU;CACvC;CAEA;CAEA,YAAYA,UAA0BC,GAAYC,gBAAyB;EACzE,MACE,UAAU,MACV,QACA,UAAU,kBACV,UAAU,eACX;EACD,KAAK,IAAI,KAAK;EACd,KAAK,iBAAiB,kBAAkB;CACzC;CAED,eAAuB;AACrB,SAAO,CAAC,KAAK,EAAE,KAAK,EAAE,oBAAoB,EAAE,KAAK,eAAe,CAAC,CAAC;CACnE;AACF;AAED,IAAa,eAAb,cAAkC,UAAU;CAC1C;CAEA,YAAYC,UAAyBC,OAAgB;EACnD,MACE,UAAU,MACV,WACA,UAAU,kBACV,UAAU,eACX;EACD,KAAK,QAAQ,SAAS;CACvB;CAED,eAAuB;AACrB,SAAO,CAAC,SAAS,EAAE,KAAK,MAAM,CAAC,CAAC;CACjC;AACF;;;;;AAMD,IAAsB,eAAtB,MAAmC,CAElC;AAED,IAAa,mBAAb,cAAsC,aAAa;CACjD;CAEA,YAAYC,UAAmB;EAC7B,OAAO;EACP,KAAK,WAAW,YAAY;CAC7B;CAED,YAAoB;AAClB,SAAO,CAAC,iBAAiB,EAAE,KAAK,UAAU;CAC3C;AACF;AAED,IAAa,sBAAb,cAAyC,aAAa;CACpD,AAAS;CAET,YAAYC,QAAiB;EAC3B,OAAO;EACP,KAAK,SAAS,UAAU;CACzB;CAED,YAAoB;AAClB,SAAO,CAAC,iBAAiB,EAAE,KAAK,QAAQ;CACzC;AACF"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
//#region src/indexes.d.ts
|
|
2
|
+
declare class StrategyMixin {
|
|
3
|
+
operator: string;
|
|
4
|
+
searchFunction: string;
|
|
5
|
+
indexFunction: string;
|
|
6
|
+
constructor(operator: string, searchFunction: string, indexFunction: string);
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Enumerator of the Distance strategies.
|
|
10
|
+
*/
|
|
11
|
+
declare class DistanceStrategy extends StrategyMixin {
|
|
12
|
+
static EUCLIDEAN: StrategyMixin;
|
|
13
|
+
static COSINE_DISTANCE: StrategyMixin;
|
|
14
|
+
static INNER_PRODUCT: StrategyMixin;
|
|
15
|
+
}
|
|
16
|
+
declare const DEFAULT_DISTANCE_STRATEGY: StrategyMixin;
|
|
17
|
+
declare const DEFAULT_INDEX_NAME_SUFFIX: string;
|
|
18
|
+
interface BaseIndexArgs {
|
|
19
|
+
name?: string;
|
|
20
|
+
distanceStrategy?: DistanceStrategy;
|
|
21
|
+
partialIndexes?: string[];
|
|
22
|
+
}
|
|
23
|
+
declare abstract class BaseIndex {
|
|
24
|
+
name?: string;
|
|
25
|
+
indexType: string;
|
|
26
|
+
distanceStrategy: DistanceStrategy;
|
|
27
|
+
partialIndexes?: string[];
|
|
28
|
+
constructor(name?: string, indexType?: string, distanceStrategy?: DistanceStrategy, partialIndexes?: string[]);
|
|
29
|
+
/**
|
|
30
|
+
* Set index query options for vector store initialization.
|
|
31
|
+
*/
|
|
32
|
+
abstract indexOptions(): string;
|
|
33
|
+
}
|
|
34
|
+
declare class ExactNearestNeighbor extends BaseIndex {
|
|
35
|
+
constructor(baseArgs?: BaseIndexArgs);
|
|
36
|
+
indexOptions(): string;
|
|
37
|
+
}
|
|
38
|
+
declare class HNSWIndex extends BaseIndex {
|
|
39
|
+
m: number;
|
|
40
|
+
efConstruction: number;
|
|
41
|
+
constructor(baseArgs?: BaseIndexArgs, m?: number, efConstruction?: number);
|
|
42
|
+
indexOptions(): string;
|
|
43
|
+
}
|
|
44
|
+
declare class IVFFlatIndex extends BaseIndex {
|
|
45
|
+
lists: number;
|
|
46
|
+
constructor(baseArgs: BaseIndexArgs, lists?: number);
|
|
47
|
+
indexOptions(): string;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Convert index attributes to string.
|
|
51
|
+
* Must be implemented by subclasses.
|
|
52
|
+
*/
|
|
53
|
+
declare abstract class QueryOptions {
|
|
54
|
+
abstract to_string(): string;
|
|
55
|
+
}
|
|
56
|
+
declare class HNSWQueryOptions extends QueryOptions {
|
|
57
|
+
efSearch: number;
|
|
58
|
+
constructor(efSearch?: number);
|
|
59
|
+
to_string(): string;
|
|
60
|
+
}
|
|
61
|
+
declare class IVFFlatQueryOptions extends QueryOptions {
|
|
62
|
+
readonly probes: number;
|
|
63
|
+
constructor(probes?: number);
|
|
64
|
+
to_string(): string;
|
|
65
|
+
}
|
|
66
|
+
//#endregion
|
|
67
|
+
export { BaseIndex, BaseIndexArgs, DEFAULT_DISTANCE_STRATEGY, DEFAULT_INDEX_NAME_SUFFIX, DistanceStrategy, ExactNearestNeighbor, HNSWIndex, HNSWQueryOptions, IVFFlatIndex, IVFFlatQueryOptions, QueryOptions };
|
|
68
|
+
//# sourceMappingURL=indexes.d.cts.map
|
package/dist/indexes.d.ts
CHANGED
|
@@ -1,65 +1,68 @@
|
|
|
1
|
+
//#region src/indexes.d.ts
|
|
1
2
|
declare class StrategyMixin {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
operator: string;
|
|
4
|
+
searchFunction: string;
|
|
5
|
+
indexFunction: string;
|
|
6
|
+
constructor(operator: string, searchFunction: string, indexFunction: string);
|
|
6
7
|
}
|
|
7
8
|
/**
|
|
8
9
|
* Enumerator of the Distance strategies.
|
|
9
10
|
*/
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
declare class DistanceStrategy extends StrategyMixin {
|
|
12
|
+
static EUCLIDEAN: StrategyMixin;
|
|
13
|
+
static COSINE_DISTANCE: StrategyMixin;
|
|
14
|
+
static INNER_PRODUCT: StrategyMixin;
|
|
14
15
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
16
|
+
declare const DEFAULT_DISTANCE_STRATEGY: StrategyMixin;
|
|
17
|
+
declare const DEFAULT_INDEX_NAME_SUFFIX: string;
|
|
18
|
+
interface BaseIndexArgs {
|
|
19
|
+
name?: string;
|
|
20
|
+
distanceStrategy?: DistanceStrategy;
|
|
21
|
+
partialIndexes?: string[];
|
|
21
22
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
23
|
+
declare abstract class BaseIndex {
|
|
24
|
+
name?: string;
|
|
25
|
+
indexType: string;
|
|
26
|
+
distanceStrategy: DistanceStrategy;
|
|
27
|
+
partialIndexes?: string[];
|
|
28
|
+
constructor(name?: string, indexType?: string, distanceStrategy?: DistanceStrategy, partialIndexes?: string[]);
|
|
29
|
+
/**
|
|
30
|
+
* Set index query options for vector store initialization.
|
|
31
|
+
*/
|
|
32
|
+
abstract indexOptions(): string;
|
|
32
33
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
declare class ExactNearestNeighbor extends BaseIndex {
|
|
35
|
+
constructor(baseArgs?: BaseIndexArgs);
|
|
36
|
+
indexOptions(): string;
|
|
36
37
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
38
|
+
declare class HNSWIndex extends BaseIndex {
|
|
39
|
+
m: number;
|
|
40
|
+
efConstruction: number;
|
|
41
|
+
constructor(baseArgs?: BaseIndexArgs, m?: number, efConstruction?: number);
|
|
42
|
+
indexOptions(): string;
|
|
42
43
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
44
|
+
declare class IVFFlatIndex extends BaseIndex {
|
|
45
|
+
lists: number;
|
|
46
|
+
constructor(baseArgs: BaseIndexArgs, lists?: number);
|
|
47
|
+
indexOptions(): string;
|
|
47
48
|
}
|
|
48
49
|
/**
|
|
49
50
|
* Convert index attributes to string.
|
|
50
51
|
* Must be implemented by subclasses.
|
|
51
52
|
*/
|
|
52
|
-
|
|
53
|
-
|
|
53
|
+
declare abstract class QueryOptions {
|
|
54
|
+
abstract to_string(): string;
|
|
54
55
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
56
|
+
declare class HNSWQueryOptions extends QueryOptions {
|
|
57
|
+
efSearch: number;
|
|
58
|
+
constructor(efSearch?: number);
|
|
59
|
+
to_string(): string;
|
|
59
60
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
61
|
+
declare class IVFFlatQueryOptions extends QueryOptions {
|
|
62
|
+
readonly probes: number;
|
|
63
|
+
constructor(probes?: number);
|
|
64
|
+
to_string(): string;
|
|
64
65
|
}
|
|
65
|
-
|
|
66
|
+
//#endregion
|
|
67
|
+
export { BaseIndex, BaseIndexArgs, DEFAULT_DISTANCE_STRATEGY, DEFAULT_INDEX_NAME_SUFFIX, DistanceStrategy, ExactNearestNeighbor, HNSWIndex, HNSWQueryOptions, IVFFlatIndex, IVFFlatQueryOptions, QueryOptions };
|
|
68
|
+
//# sourceMappingURL=indexes.d.ts.map
|