langchain 0.0.174 → 0.0.175

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,116 @@
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
2
+ // eslint-disable-next-line import/no-extraneous-dependencies
3
+ import { makeFunctionReference, } from "convex/server";
4
+ import { BaseListChatMessageHistory } from "../../schema/index.js";
5
+ import { mapChatMessagesToStoredMessages, mapStoredMessagesToChatMessages, } from "./utils.js";
6
+ export class ConvexChatMessageHistory extends BaseListChatMessageHistory {
7
+ constructor(config) {
8
+ super();
9
+ Object.defineProperty(this, "lc_namespace", {
10
+ enumerable: true,
11
+ configurable: true,
12
+ writable: true,
13
+ value: ["langchain", "stores", "message", "convex"]
14
+ });
15
+ Object.defineProperty(this, "ctx", {
16
+ enumerable: true,
17
+ configurable: true,
18
+ writable: true,
19
+ value: void 0
20
+ });
21
+ Object.defineProperty(this, "sessionId", {
22
+ enumerable: true,
23
+ configurable: true,
24
+ writable: true,
25
+ value: void 0
26
+ });
27
+ Object.defineProperty(this, "table", {
28
+ enumerable: true,
29
+ configurable: true,
30
+ writable: true,
31
+ value: void 0
32
+ });
33
+ Object.defineProperty(this, "index", {
34
+ enumerable: true,
35
+ configurable: true,
36
+ writable: true,
37
+ value: void 0
38
+ });
39
+ Object.defineProperty(this, "sessionIdField", {
40
+ enumerable: true,
41
+ configurable: true,
42
+ writable: true,
43
+ value: void 0
44
+ });
45
+ Object.defineProperty(this, "messageTextFieldName", {
46
+ enumerable: true,
47
+ configurable: true,
48
+ writable: true,
49
+ value: void 0
50
+ });
51
+ Object.defineProperty(this, "insert", {
52
+ enumerable: true,
53
+ configurable: true,
54
+ writable: true,
55
+ value: void 0
56
+ });
57
+ Object.defineProperty(this, "lookup", {
58
+ enumerable: true,
59
+ configurable: true,
60
+ writable: true,
61
+ value: void 0
62
+ });
63
+ Object.defineProperty(this, "deleteMany", {
64
+ enumerable: true,
65
+ configurable: true,
66
+ writable: true,
67
+ value: void 0
68
+ });
69
+ this.ctx = config.ctx;
70
+ this.sessionId = config.sessionId;
71
+ this.table = config.table ?? "messages";
72
+ this.index = config.index ?? "bySessionId";
73
+ this.sessionIdField =
74
+ config.sessionIdField ?? "sessionId";
75
+ this.messageTextFieldName =
76
+ config.messageTextFieldName ?? "message";
77
+ this.insert =
78
+ config.insert ?? makeFunctionReference("langchain/db:insert");
79
+ this.lookup =
80
+ config.lookup ?? makeFunctionReference("langchain/db:lookup");
81
+ this.deleteMany =
82
+ config.deleteMany ??
83
+ makeFunctionReference("langchain/db:deleteMany");
84
+ }
85
+ async getMessages() {
86
+ const convexDocuments = await this.ctx.runQuery(this.lookup, {
87
+ table: this.table,
88
+ index: this.index,
89
+ keyField: this.sessionIdField,
90
+ key: this.sessionId,
91
+ });
92
+ return mapStoredMessagesToChatMessages(convexDocuments.map((doc) => doc[this.messageTextFieldName]));
93
+ }
94
+ async addMessage(message) {
95
+ const messages = mapChatMessagesToStoredMessages([message]);
96
+ // TODO: Remove chunking when Convex handles the concurrent requests correctly
97
+ const PAGE_SIZE = 16;
98
+ for (let i = 0; i < messages.length; i += PAGE_SIZE) {
99
+ await Promise.all(messages.slice(i, i + PAGE_SIZE).map((message) => this.ctx.runMutation(this.insert, {
100
+ table: this.table,
101
+ document: {
102
+ [this.sessionIdField]: this.sessionId,
103
+ [this.messageTextFieldName]: message,
104
+ },
105
+ })));
106
+ }
107
+ }
108
+ async clear() {
109
+ await this.ctx.runMutation(this.deleteMany, {
110
+ table: this.table,
111
+ index: this.index,
112
+ keyField: this.sessionIdField,
113
+ key: this.sessionId,
114
+ });
115
+ }
116
+ }
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+ /* eslint-disable spaced-comment */
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.deleteMany = exports.upsert = exports.lookup = exports.insert = exports.get = void 0;
5
+ // eslint-disable-next-line import/no-extraneous-dependencies
6
+ const server_1 = require("convex/server");
7
+ // eslint-disable-next-line import/no-extraneous-dependencies
8
+ const values_1 = require("convex/values");
9
+ exports.get = (0, server_1.internalQueryGeneric)({
10
+ args: {
11
+ id: /*#__PURE__*/ values_1.v.string(),
12
+ },
13
+ handler: async (ctx, args) => {
14
+ const result = await ctx.db.get(args.id);
15
+ return result;
16
+ },
17
+ });
18
+ exports.insert = (0, server_1.internalMutationGeneric)({
19
+ args: {
20
+ table: /*#__PURE__*/ values_1.v.string(),
21
+ document: /*#__PURE__*/ values_1.v.any(),
22
+ },
23
+ handler: async (ctx, args) => {
24
+ await ctx.db.insert(args.table, args.document);
25
+ },
26
+ });
27
+ exports.lookup = (0, server_1.internalQueryGeneric)({
28
+ args: {
29
+ table: /*#__PURE__*/ values_1.v.string(),
30
+ index: /*#__PURE__*/ values_1.v.string(),
31
+ keyField: /*#__PURE__*/ values_1.v.string(),
32
+ key: /*#__PURE__*/ values_1.v.string(),
33
+ },
34
+ handler: async (ctx, args) => {
35
+ const result = await ctx.db
36
+ .query(args.table)
37
+ .withIndex(args.index, (q) => q.eq(args.keyField, args.key))
38
+ .collect();
39
+ return result;
40
+ },
41
+ });
42
+ exports.upsert = (0, server_1.internalMutationGeneric)({
43
+ args: {
44
+ table: /*#__PURE__*/ values_1.v.string(),
45
+ index: /*#__PURE__*/ values_1.v.string(),
46
+ keyField: /*#__PURE__*/ values_1.v.string(),
47
+ key: /*#__PURE__*/ values_1.v.string(),
48
+ document: /*#__PURE__*/ values_1.v.any(),
49
+ },
50
+ handler: async (ctx, args) => {
51
+ const existing = await ctx.db
52
+ .query(args.table)
53
+ .withIndex(args.index, (q) => q.eq(args.keyField, args.key))
54
+ .unique();
55
+ if (existing !== null) {
56
+ await ctx.db.replace(existing._id, args.document);
57
+ }
58
+ else {
59
+ await ctx.db.insert(args.table, args.document);
60
+ }
61
+ },
62
+ });
63
+ exports.deleteMany = (0, server_1.internalMutationGeneric)({
64
+ args: {
65
+ table: /*#__PURE__*/ values_1.v.string(),
66
+ index: /*#__PURE__*/ values_1.v.string(),
67
+ keyField: /*#__PURE__*/ values_1.v.string(),
68
+ key: /*#__PURE__*/ values_1.v.string(),
69
+ },
70
+ handler: async (ctx, args) => {
71
+ const existing = await ctx.db
72
+ .query(args.table)
73
+ .withIndex(args.index, (q) => q.eq(args.keyField, args.key))
74
+ .collect();
75
+ await Promise.all(existing.map((doc) => ctx.db.delete(doc._id)));
76
+ },
77
+ });
@@ -0,0 +1,26 @@
1
+ export declare const get: import("convex/server").RegisteredQuery<"internal", {
2
+ id: string;
3
+ }, Promise<any>>;
4
+ export declare const insert: import("convex/server").RegisteredMutation<"internal", {
5
+ document: any;
6
+ table: string;
7
+ }, Promise<void>>;
8
+ export declare const lookup: import("convex/server").RegisteredQuery<"internal", {
9
+ key: string;
10
+ index: string;
11
+ table: string;
12
+ keyField: string;
13
+ }, Promise<any[]>>;
14
+ export declare const upsert: import("convex/server").RegisteredMutation<"internal", {
15
+ key: string;
16
+ index: string;
17
+ document: any;
18
+ table: string;
19
+ keyField: string;
20
+ }, Promise<void>>;
21
+ export declare const deleteMany: import("convex/server").RegisteredMutation<"internal", {
22
+ key: string;
23
+ index: string;
24
+ table: string;
25
+ keyField: string;
26
+ }, Promise<void>>;
@@ -0,0 +1,74 @@
1
+ /* eslint-disable spaced-comment */
2
+ // eslint-disable-next-line import/no-extraneous-dependencies
3
+ import { internalQueryGeneric as internalQuery, internalMutationGeneric as internalMutation, } from "convex/server";
4
+ // eslint-disable-next-line import/no-extraneous-dependencies
5
+ import { v } from "convex/values";
6
+ export const get = /*#__PURE__*/ internalQuery({
7
+ args: {
8
+ id: /*#__PURE__*/ v.string(),
9
+ },
10
+ handler: async (ctx, args) => {
11
+ const result = await ctx.db.get(args.id);
12
+ return result;
13
+ },
14
+ });
15
+ export const insert = /*#__PURE__*/ internalMutation({
16
+ args: {
17
+ table: /*#__PURE__*/ v.string(),
18
+ document: /*#__PURE__*/ v.any(),
19
+ },
20
+ handler: async (ctx, args) => {
21
+ await ctx.db.insert(args.table, args.document);
22
+ },
23
+ });
24
+ export const lookup = /*#__PURE__*/ internalQuery({
25
+ args: {
26
+ table: /*#__PURE__*/ v.string(),
27
+ index: /*#__PURE__*/ v.string(),
28
+ keyField: /*#__PURE__*/ v.string(),
29
+ key: /*#__PURE__*/ v.string(),
30
+ },
31
+ handler: async (ctx, args) => {
32
+ const result = await ctx.db
33
+ .query(args.table)
34
+ .withIndex(args.index, (q) => q.eq(args.keyField, args.key))
35
+ .collect();
36
+ return result;
37
+ },
38
+ });
39
+ export const upsert = /*#__PURE__*/ internalMutation({
40
+ args: {
41
+ table: /*#__PURE__*/ v.string(),
42
+ index: /*#__PURE__*/ v.string(),
43
+ keyField: /*#__PURE__*/ v.string(),
44
+ key: /*#__PURE__*/ v.string(),
45
+ document: /*#__PURE__*/ v.any(),
46
+ },
47
+ handler: async (ctx, args) => {
48
+ const existing = await ctx.db
49
+ .query(args.table)
50
+ .withIndex(args.index, (q) => q.eq(args.keyField, args.key))
51
+ .unique();
52
+ if (existing !== null) {
53
+ await ctx.db.replace(existing._id, args.document);
54
+ }
55
+ else {
56
+ await ctx.db.insert(args.table, args.document);
57
+ }
58
+ },
59
+ });
60
+ export const deleteMany = /*#__PURE__*/ internalMutation({
61
+ args: {
62
+ table: /*#__PURE__*/ v.string(),
63
+ index: /*#__PURE__*/ v.string(),
64
+ keyField: /*#__PURE__*/ v.string(),
65
+ key: /*#__PURE__*/ v.string(),
66
+ },
67
+ handler: async (ctx, args) => {
68
+ const existing = await ctx.db
69
+ .query(args.table)
70
+ .withIndex(args.index, (q) => q.eq(args.keyField, args.key))
71
+ .collect();
72
+ await Promise.all(existing.map((doc) => ctx.db.delete(doc._id)));
73
+ },
74
+ });
@@ -0,0 +1,177 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ConvexVectorStore = void 0;
4
+ // eslint-disable-next-line import/no-extraneous-dependencies
5
+ const server_1 = require("convex/server");
6
+ const document_js_1 = require("../document.cjs");
7
+ const base_js_1 = require("./base.cjs");
8
+ /**
9
+ * Class that is a wrapper around Convex storage and vector search. It is used
10
+ * to insert embeddings in Convex documents with a vector search index,
11
+ * and perform a vector search on them.
12
+ *
13
+ * ConvexVectorStore does NOT implement maxMarginalRelevanceSearch.
14
+ */
15
+ class ConvexVectorStore extends base_js_1.VectorStore {
16
+ _vectorstoreType() {
17
+ return "convex";
18
+ }
19
+ constructor(embeddings, config) {
20
+ super(embeddings, config);
21
+ Object.defineProperty(this, "ctx", {
22
+ enumerable: true,
23
+ configurable: true,
24
+ writable: true,
25
+ value: void 0
26
+ });
27
+ Object.defineProperty(this, "table", {
28
+ enumerable: true,
29
+ configurable: true,
30
+ writable: true,
31
+ value: void 0
32
+ });
33
+ Object.defineProperty(this, "index", {
34
+ enumerable: true,
35
+ configurable: true,
36
+ writable: true,
37
+ value: void 0
38
+ });
39
+ Object.defineProperty(this, "textField", {
40
+ enumerable: true,
41
+ configurable: true,
42
+ writable: true,
43
+ value: void 0
44
+ });
45
+ Object.defineProperty(this, "embeddingField", {
46
+ enumerable: true,
47
+ configurable: true,
48
+ writable: true,
49
+ value: void 0
50
+ });
51
+ Object.defineProperty(this, "metadataField", {
52
+ enumerable: true,
53
+ configurable: true,
54
+ writable: true,
55
+ value: void 0
56
+ });
57
+ Object.defineProperty(this, "insert", {
58
+ enumerable: true,
59
+ configurable: true,
60
+ writable: true,
61
+ value: void 0
62
+ });
63
+ Object.defineProperty(this, "get", {
64
+ enumerable: true,
65
+ configurable: true,
66
+ writable: true,
67
+ value: void 0
68
+ });
69
+ this.ctx = config.ctx;
70
+ this.table = config.table ?? "documents";
71
+ this.index = config.index ?? "byEmbedding";
72
+ this.textField = config.textField ?? "text";
73
+ this.embeddingField =
74
+ config.embeddingField ?? "embedding";
75
+ this.metadataField =
76
+ config.metadataField ?? "metadata";
77
+ this.insert =
78
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
79
+ config.insert ?? (0, server_1.makeFunctionReference)("langchain/db:insert");
80
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
81
+ this.get = config.get ?? (0, server_1.makeFunctionReference)("langchain/db:get");
82
+ }
83
+ /**
84
+ * Add vectors and their corresponding documents to the Convex table.
85
+ * @param vectors Vectors to be added.
86
+ * @param documents Corresponding documents to be added.
87
+ * @returns Promise that resolves when the vectors and documents have been added.
88
+ */
89
+ async addVectors(vectors, documents) {
90
+ const convexDocuments = vectors.map((embedding, idx) => ({
91
+ [this.textField]: documents[idx].pageContent,
92
+ [this.embeddingField]: embedding,
93
+ [this.metadataField]: documents[idx].metadata,
94
+ }));
95
+ // TODO: Remove chunking when Convex handles the concurrent requests correctly
96
+ const PAGE_SIZE = 16;
97
+ for (let i = 0; i < convexDocuments.length; i += PAGE_SIZE) {
98
+ await Promise.all(convexDocuments.slice(i, i + PAGE_SIZE).map((document) => this.ctx.runMutation(this.insert, {
99
+ table: this.table,
100
+ document,
101
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
102
+ })));
103
+ }
104
+ }
105
+ /**
106
+ * Add documents to the Convex table. It first converts
107
+ * the documents to vectors using the embeddings and then calls the
108
+ * addVectors method.
109
+ * @param documents Documents to be added.
110
+ * @returns Promise that resolves when the documents have been added.
111
+ */
112
+ async addDocuments(documents) {
113
+ const texts = documents.map(({ pageContent }) => pageContent);
114
+ return this.addVectors(await this.embeddings.embedDocuments(texts), documents);
115
+ }
116
+ /**
117
+ * Similarity search on the vectors stored in the
118
+ * Convex table. It returns a list of documents and their
119
+ * corresponding similarity scores.
120
+ * @param query Query vector for the similarity search.
121
+ * @param k Number of nearest neighbors to return.
122
+ * @param filter Optional filter to be applied.
123
+ * @returns Promise that resolves to a list of documents and their corresponding similarity scores.
124
+ */
125
+ async similaritySearchVectorWithScore(query, k, filter) {
126
+ const idsAndScores = await this.ctx.vectorSearch(this.table, this.index, {
127
+ vector: query,
128
+ limit: k,
129
+ filter: filter?.filter,
130
+ });
131
+ const documents = await Promise.all(idsAndScores.map(({ _id }) =>
132
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
133
+ this.ctx.runQuery(this.get, { id: _id })));
134
+ return documents.map(({ [this.textField]: text, [this.embeddingField]: embedding, [this.metadataField]: metadata, }, idx) => [
135
+ new document_js_1.Document({
136
+ pageContent: text,
137
+ metadata: {
138
+ ...metadata,
139
+ ...(filter?.includeEmbeddings ? { embedding } : null),
140
+ },
141
+ }),
142
+ idsAndScores[idx]._score,
143
+ ]);
144
+ }
145
+ /**
146
+ * Static method to create an instance of ConvexVectorStore from a
147
+ * list of texts. It first converts the texts to vectors and then adds
148
+ * them to the Convex table.
149
+ * @param texts List of texts to be converted to vectors.
150
+ * @param metadatas Metadata for the texts.
151
+ * @param embeddings Embeddings to be used for conversion.
152
+ * @param dbConfig Database configuration for Convex.
153
+ * @returns Promise that resolves to a new instance of ConvexVectorStore.
154
+ */
155
+ static async fromTexts(texts, metadatas, embeddings, dbConfig) {
156
+ const docs = texts.map((text, i) => new document_js_1.Document({
157
+ pageContent: text,
158
+ metadata: Array.isArray(metadatas) ? metadatas[i] : metadatas,
159
+ }));
160
+ return ConvexVectorStore.fromDocuments(docs, embeddings, dbConfig);
161
+ }
162
+ /**
163
+ * Static method to create an instance of ConvexVectorStore from a
164
+ * list of documents. It first converts the documents to vectors and then
165
+ * adds them to the Convex table.
166
+ * @param docs List of documents to be converted to vectors.
167
+ * @param embeddings Embeddings to be used for conversion.
168
+ * @param dbConfig Database configuration for Convex.
169
+ * @returns Promise that resolves to a new instance of ConvexVectorStore.
170
+ */
171
+ static async fromDocuments(docs, embeddings, dbConfig) {
172
+ const instance = new this(embeddings, dbConfig);
173
+ await instance.addDocuments(docs);
174
+ return instance;
175
+ }
176
+ }
177
+ exports.ConvexVectorStore = ConvexVectorStore;
@@ -0,0 +1,113 @@
1
+ import { DocumentByInfo, FieldPaths, FilterExpression, FunctionReference, GenericActionCtx, GenericDataModel, GenericTableInfo, NamedTableInfo, NamedVectorIndex, TableNamesInDataModel, VectorFilterBuilder, VectorIndexNames } from "convex/server";
2
+ import { Document } from "../document.js";
3
+ import { Embeddings } from "../embeddings/base.js";
4
+ import { VectorStore } from "./base.js";
5
+ /**
6
+ * Type that defines the config required to initialize the
7
+ * ConvexVectorStore class. It includes the table name,
8
+ * index name, text field name, and embedding field name.
9
+ */
10
+ export type ConvexVectorStoreConfig<DataModel extends GenericDataModel, TableName extends TableNamesInDataModel<DataModel>, IndexName extends VectorIndexNames<NamedTableInfo<DataModel, TableName>>, TextFieldName extends FieldPaths<NamedTableInfo<DataModel, TableName>>, EmbeddingFieldName extends FieldPaths<NamedTableInfo<DataModel, TableName>>, MetadataFieldName extends FieldPaths<NamedTableInfo<DataModel, TableName>>, InsertMutation extends FunctionReference<"mutation", "internal", {
11
+ table: string;
12
+ document: object;
13
+ }>, GetQuery extends FunctionReference<"query", "internal", {
14
+ id: string;
15
+ }, object | null>> = {
16
+ readonly ctx: GenericActionCtx<DataModel>;
17
+ readonly table?: TableName;
18
+ readonly index?: IndexName;
19
+ readonly textField?: TextFieldName;
20
+ readonly embeddingField?: EmbeddingFieldName;
21
+ readonly metadataField?: MetadataFieldName;
22
+ readonly insert?: InsertMutation;
23
+ readonly get?: GetQuery;
24
+ };
25
+ /**
26
+ * Class that is a wrapper around Convex storage and vector search. It is used
27
+ * to insert embeddings in Convex documents with a vector search index,
28
+ * and perform a vector search on them.
29
+ *
30
+ * ConvexVectorStore does NOT implement maxMarginalRelevanceSearch.
31
+ */
32
+ export declare class ConvexVectorStore<DataModel extends GenericDataModel, TableName extends TableNamesInDataModel<DataModel>, IndexName extends VectorIndexNames<NamedTableInfo<DataModel, TableName>>, TextFieldName extends FieldPaths<NamedTableInfo<DataModel, TableName>>, EmbeddingFieldName extends FieldPaths<NamedTableInfo<DataModel, TableName>>, MetadataFieldName extends FieldPaths<NamedTableInfo<DataModel, TableName>>, InsertMutation extends FunctionReference<"mutation", "internal", {
33
+ table: string;
34
+ document: object;
35
+ }>, GetQuery extends FunctionReference<"query", "internal", {
36
+ id: string;
37
+ }, object | null>> extends VectorStore {
38
+ /**
39
+ * Type that defines the filter used in the
40
+ * similaritySearchVectorWithScore and maxMarginalRelevanceSearch methods.
41
+ * It includes limit, filter and a flag to include embeddings.
42
+ */
43
+ FilterType: {
44
+ filter?: (q: VectorFilterBuilder<DocumentByInfo<GenericTableInfo>, NamedVectorIndex<NamedTableInfo<DataModel, TableName>, IndexName>>) => FilterExpression<boolean>;
45
+ includeEmbeddings?: boolean;
46
+ };
47
+ private readonly ctx;
48
+ private readonly table;
49
+ private readonly index;
50
+ private readonly textField;
51
+ private readonly embeddingField;
52
+ private readonly metadataField;
53
+ private readonly insert;
54
+ private readonly get;
55
+ _vectorstoreType(): string;
56
+ constructor(embeddings: Embeddings, config: ConvexVectorStoreConfig<DataModel, TableName, IndexName, TextFieldName, EmbeddingFieldName, MetadataFieldName, InsertMutation, GetQuery>);
57
+ /**
58
+ * Add vectors and their corresponding documents to the Convex table.
59
+ * @param vectors Vectors to be added.
60
+ * @param documents Corresponding documents to be added.
61
+ * @returns Promise that resolves when the vectors and documents have been added.
62
+ */
63
+ addVectors(vectors: number[][], documents: Document[]): Promise<void>;
64
+ /**
65
+ * Add documents to the Convex table. It first converts
66
+ * the documents to vectors using the embeddings and then calls the
67
+ * addVectors method.
68
+ * @param documents Documents to be added.
69
+ * @returns Promise that resolves when the documents have been added.
70
+ */
71
+ addDocuments(documents: Document[]): Promise<void>;
72
+ /**
73
+ * Similarity search on the vectors stored in the
74
+ * Convex table. It returns a list of documents and their
75
+ * corresponding similarity scores.
76
+ * @param query Query vector for the similarity search.
77
+ * @param k Number of nearest neighbors to return.
78
+ * @param filter Optional filter to be applied.
79
+ * @returns Promise that resolves to a list of documents and their corresponding similarity scores.
80
+ */
81
+ similaritySearchVectorWithScore(query: number[], k: number, filter?: this["FilterType"]): Promise<[Document, number][]>;
82
+ /**
83
+ * Static method to create an instance of ConvexVectorStore from a
84
+ * list of texts. It first converts the texts to vectors and then adds
85
+ * them to the Convex table.
86
+ * @param texts List of texts to be converted to vectors.
87
+ * @param metadatas Metadata for the texts.
88
+ * @param embeddings Embeddings to be used for conversion.
89
+ * @param dbConfig Database configuration for Convex.
90
+ * @returns Promise that resolves to a new instance of ConvexVectorStore.
91
+ */
92
+ static fromTexts<DataModel extends GenericDataModel, TableName extends TableNamesInDataModel<DataModel>, IndexName extends VectorIndexNames<NamedTableInfo<DataModel, TableName>>, TextFieldName extends FieldPaths<NamedTableInfo<DataModel, TableName>>, EmbeddingFieldName extends FieldPaths<NamedTableInfo<DataModel, TableName>>, MetadataFieldName extends FieldPaths<NamedTableInfo<DataModel, TableName>>, InsertMutation extends FunctionReference<"mutation", "internal", {
93
+ table: string;
94
+ document: object;
95
+ }>, GetQuery extends FunctionReference<"query", "internal", {
96
+ id: string;
97
+ }, object | null>>(texts: string[], metadatas: object[] | object, embeddings: Embeddings, dbConfig: ConvexVectorStoreConfig<DataModel, TableName, IndexName, TextFieldName, EmbeddingFieldName, MetadataFieldName, InsertMutation, GetQuery>): Promise<ConvexVectorStore<DataModel, TableName, IndexName, TextFieldName, EmbeddingFieldName, MetadataFieldName, InsertMutation, GetQuery>>;
98
+ /**
99
+ * Static method to create an instance of ConvexVectorStore from a
100
+ * list of documents. It first converts the documents to vectors and then
101
+ * adds them to the Convex table.
102
+ * @param docs List of documents to be converted to vectors.
103
+ * @param embeddings Embeddings to be used for conversion.
104
+ * @param dbConfig Database configuration for Convex.
105
+ * @returns Promise that resolves to a new instance of ConvexVectorStore.
106
+ */
107
+ static fromDocuments<DataModel extends GenericDataModel, TableName extends TableNamesInDataModel<DataModel>, IndexName extends VectorIndexNames<NamedTableInfo<DataModel, TableName>>, TextFieldName extends FieldPaths<NamedTableInfo<DataModel, TableName>>, EmbeddingFieldName extends FieldPaths<NamedTableInfo<DataModel, TableName>>, MetadataFieldName extends FieldPaths<NamedTableInfo<DataModel, TableName>>, InsertMutation extends FunctionReference<"mutation", "internal", {
108
+ table: string;
109
+ document: object;
110
+ }>, GetQuery extends FunctionReference<"query", "internal", {
111
+ id: string;
112
+ }, object | null>>(docs: Document[], embeddings: Embeddings, dbConfig: ConvexVectorStoreConfig<DataModel, TableName, IndexName, TextFieldName, EmbeddingFieldName, MetadataFieldName, InsertMutation, GetQuery>): Promise<ConvexVectorStore<DataModel, TableName, IndexName, TextFieldName, EmbeddingFieldName, MetadataFieldName, InsertMutation, GetQuery>>;
113
+ }