langchain 0.0.144 → 0.0.146
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/api/api_chain.d.ts +1 -1
- package/dist/chains/openai_functions/extraction.d.ts +1 -1
- package/dist/chains/openai_functions/openapi.d.ts +1 -1
- package/dist/chains/openai_functions/structured_output.d.ts +1 -1
- package/dist/chains/openai_functions/tagging.d.ts +1 -1
- package/dist/chat_models/anthropic.d.ts +2 -2
- package/dist/embeddings/ollama.cjs +114 -0
- package/dist/embeddings/ollama.d.ts +34 -0
- package/dist/embeddings/ollama.js +110 -0
- package/dist/hub.cjs +14 -0
- package/dist/hub.d.ts +14 -0
- package/dist/hub.js +14 -0
- package/dist/load/import_constants.cjs +1 -0
- package/dist/load/import_constants.js +1 -0
- package/dist/load/import_map.cjs +3 -2
- package/dist/load/import_map.d.ts +1 -0
- package/dist/load/import_map.js +1 -0
- package/dist/schema/index.cjs +5 -22
- package/dist/schema/index.d.ts +1 -5
- package/dist/schema/index.js +5 -22
- package/dist/types/googlevertexai-types.d.ts +1 -1
- package/dist/vectorstores/voy.cjs +158 -0
- package/dist/vectorstores/voy.d.ts +73 -0
- package/dist/vectorstores/voy.js +154 -0
- package/embeddings/ollama.cjs +1 -0
- package/embeddings/ollama.d.ts +1 -0
- package/embeddings/ollama.js +1 -0
- package/package.json +32 -76
- package/vectorstores/voy.cjs +1 -0
- package/vectorstores/voy.d.ts +1 -0
- package/vectorstores/voy.js +1 -0
- package/chat_models.cjs +0 -1
- package/chat_models.d.ts +0 -1
- package/chat_models.js +0 -1
- package/dist/chat_models/index.cjs +0 -11
- package/dist/chat_models/index.d.ts +0 -3
- package/dist/chat_models/index.js +0 -4
- package/dist/document_loaders/index.cjs +0 -40
- package/dist/document_loaders/index.d.ts +0 -18
- package/dist/document_loaders/index.js +0 -18
- package/dist/embeddings/index.cjs +0 -12
- package/dist/embeddings/index.d.ts +0 -4
- package/dist/embeddings/index.js +0 -5
- package/dist/index.cjs +0 -12
- package/dist/index.d.ts +0 -3
- package/dist/index.js +0 -4
- package/dist/llms/index.cjs +0 -18
- package/dist/llms/index.d.ts +0 -6
- package/dist/llms/index.js +0 -7
- package/dist/retrievers/index.cjs +0 -14
- package/dist/retrievers/index.d.ts +0 -5
- package/dist/retrievers/index.js +0 -6
- package/dist/vectorstores/index.cjs +0 -17
- package/dist/vectorstores/index.d.ts +0 -6
- package/dist/vectorstores/index.js +0 -7
- package/document_loaders.cjs +0 -1
- package/document_loaders.d.ts +0 -1
- package/document_loaders.js +0 -1
- package/embeddings.cjs +0 -1
- package/embeddings.d.ts +0 -1
- package/embeddings.js +0 -1
- package/llms.cjs +0 -1
- package/llms.d.ts +0 -1
- package/llms.js +0 -1
- package/retrievers.cjs +0 -1
- package/retrievers.d.ts +0 -1
- package/retrievers.js +0 -1
- package/vectorstores.cjs +0 -1
- package/vectorstores.d.ts +0 -1
- package/vectorstores.js +0 -1
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.VoyVectorStore = void 0;
|
|
4
|
+
const base_js_1 = require("./base.cjs");
|
|
5
|
+
const document_js_1 = require("../document.cjs");
|
|
6
|
+
/**
|
|
7
|
+
* Class that extends `VectorStore`. It allows to perform similarity search using
|
|
8
|
+
* Voi similarity search engine. The class requires passing Voy Client as an input parameter.
|
|
9
|
+
*/
|
|
10
|
+
class VoyVectorStore extends base_js_1.VectorStore {
|
|
11
|
+
_vectorstoreType() {
|
|
12
|
+
return "voi";
|
|
13
|
+
}
|
|
14
|
+
constructor(client, embeddings) {
|
|
15
|
+
super(embeddings, {});
|
|
16
|
+
Object.defineProperty(this, "client", {
|
|
17
|
+
enumerable: true,
|
|
18
|
+
configurable: true,
|
|
19
|
+
writable: true,
|
|
20
|
+
value: void 0
|
|
21
|
+
});
|
|
22
|
+
Object.defineProperty(this, "numDimensions", {
|
|
23
|
+
enumerable: true,
|
|
24
|
+
configurable: true,
|
|
25
|
+
writable: true,
|
|
26
|
+
value: null
|
|
27
|
+
});
|
|
28
|
+
Object.defineProperty(this, "docstore", {
|
|
29
|
+
enumerable: true,
|
|
30
|
+
configurable: true,
|
|
31
|
+
writable: true,
|
|
32
|
+
value: []
|
|
33
|
+
});
|
|
34
|
+
this.client = client;
|
|
35
|
+
this.embeddings = embeddings;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Adds documents to the Voy database. The documents are embedded using embeddings provided while instantiating the class.
|
|
39
|
+
* @param documents An array of `Document` instances associated with the vectors.
|
|
40
|
+
*/
|
|
41
|
+
async addDocuments(documents) {
|
|
42
|
+
const texts = documents.map(({ pageContent }) => pageContent);
|
|
43
|
+
if (documents.length === 0) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
const firstVector = (await this.embeddings.embedDocuments(texts.slice(0, 1)))[0];
|
|
47
|
+
if (this.numDimensions === null) {
|
|
48
|
+
this.numDimensions = firstVector.length;
|
|
49
|
+
}
|
|
50
|
+
else if (this.numDimensions !== firstVector.length) {
|
|
51
|
+
throw new Error(`Vectors must have the same length as the number of dimensions (${this.numDimensions})`);
|
|
52
|
+
}
|
|
53
|
+
const restResults = await this.embeddings.embedDocuments(texts.slice(1));
|
|
54
|
+
await this.addVectors([firstVector, ...restResults], documents);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Adds vectors to the Voy database. The vectors are associated with
|
|
58
|
+
* the provided documents.
|
|
59
|
+
* @param vectors An array of vectors to be added to the database.
|
|
60
|
+
* @param documents An array of `Document` instances associated with the vectors.
|
|
61
|
+
*/
|
|
62
|
+
async addVectors(vectors, documents) {
|
|
63
|
+
if (vectors.length === 0) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
if (this.numDimensions === null) {
|
|
67
|
+
this.numDimensions = vectors[0].length;
|
|
68
|
+
}
|
|
69
|
+
if (vectors.length !== documents.length) {
|
|
70
|
+
throw new Error(`Vectors and metadata must have the same length`);
|
|
71
|
+
}
|
|
72
|
+
if (!vectors.every((v) => v.length === this.numDimensions)) {
|
|
73
|
+
throw new Error(`Vectors must have the same length as the number of dimensions (${this.numDimensions})`);
|
|
74
|
+
}
|
|
75
|
+
vectors.forEach((item, idx) => {
|
|
76
|
+
const doc = documents[idx];
|
|
77
|
+
this.docstore.push({ embeddings: item, document: doc });
|
|
78
|
+
});
|
|
79
|
+
const embeddings = this.docstore.map((item, idx) => ({
|
|
80
|
+
id: String(idx),
|
|
81
|
+
embeddings: item.embeddings,
|
|
82
|
+
title: "",
|
|
83
|
+
url: "",
|
|
84
|
+
}));
|
|
85
|
+
this.client.index({ embeddings });
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Searches for vectors in the Voy database that are similar to the
|
|
89
|
+
* provided query vector.
|
|
90
|
+
* @param query The query vector.
|
|
91
|
+
* @param k The number of similar vectors to return.
|
|
92
|
+
* @returns A promise that resolves with an array of tuples, each containing a `Document` instance and a similarity score.
|
|
93
|
+
*/
|
|
94
|
+
async similaritySearchVectorWithScore(query, k) {
|
|
95
|
+
if (this.numDimensions === null) {
|
|
96
|
+
throw new Error("There aren't any elements in the index yet.");
|
|
97
|
+
}
|
|
98
|
+
if (query.length !== this.numDimensions) {
|
|
99
|
+
throw new Error(`Query vector must have the same length as the number of dimensions (${this.numDimensions})`);
|
|
100
|
+
}
|
|
101
|
+
const itemsToQuery = Math.min(this.docstore.length, k);
|
|
102
|
+
if (itemsToQuery > this.docstore.length) {
|
|
103
|
+
console.warn(`k (${k}) is greater than the number of elements in the index (${this.docstore.length}), setting k to ${itemsToQuery}`);
|
|
104
|
+
}
|
|
105
|
+
const results = this.client.search(new Float32Array(query), itemsToQuery);
|
|
106
|
+
return results.neighbors.map(({ id }, idx) => [this.docstore[parseInt(id, 10)].document, idx]);
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Method to delete data from the Voy index. It can delete data based
|
|
110
|
+
* on specific IDs or a filter.
|
|
111
|
+
* @param params Object that includes either an array of IDs or a filter for the data to be deleted.
|
|
112
|
+
* @returns Promise that resolves when the deletion is complete.
|
|
113
|
+
*/
|
|
114
|
+
async delete(params) {
|
|
115
|
+
if (params.deleteAll === true) {
|
|
116
|
+
await this.client.clear();
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
throw new Error(`You must provide a "deleteAll" parameter.`);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Creates a new `VoyVectorStore` instance from an array of text strings. The text
|
|
124
|
+
* strings are converted to `Document` instances and added to the Voy
|
|
125
|
+
* database.
|
|
126
|
+
* @param texts An array of text strings.
|
|
127
|
+
* @param metadatas An array of metadata objects or a single metadata object. If an array is provided, it must have the same length as the `texts` array.
|
|
128
|
+
* @param embeddings An `Embeddings` instance used to generate embeddings for the documents.
|
|
129
|
+
* @param client An instance of Voy client to use in the underlying operations.
|
|
130
|
+
* @returns A promise that resolves with a new `VoyVectorStore` instance.
|
|
131
|
+
*/
|
|
132
|
+
static async fromTexts(texts, metadatas, embeddings, client) {
|
|
133
|
+
const docs = [];
|
|
134
|
+
for (let i = 0; i < texts.length; i += 1) {
|
|
135
|
+
const metadata = Array.isArray(metadatas) ? metadatas[i] : metadatas;
|
|
136
|
+
const newDoc = new document_js_1.Document({
|
|
137
|
+
pageContent: texts[i],
|
|
138
|
+
metadata,
|
|
139
|
+
});
|
|
140
|
+
docs.push(newDoc);
|
|
141
|
+
}
|
|
142
|
+
return VoyVectorStore.fromDocuments(docs, embeddings, client);
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Creates a new `VoyVectorStore` instance from an array of `Document` instances.
|
|
146
|
+
* The documents are added to the Voy database.
|
|
147
|
+
* @param docs An array of `Document` instances.
|
|
148
|
+
* @param embeddings An `Embeddings` instance used to generate embeddings for the documents.
|
|
149
|
+
* @param client An instance of Voy client to use in the underlying operations.
|
|
150
|
+
* @returns A promise that resolves with a new `VoyVectorStore` instance.
|
|
151
|
+
*/
|
|
152
|
+
static async fromDocuments(docs, embeddings, client) {
|
|
153
|
+
const instance = new VoyVectorStore(client, embeddings);
|
|
154
|
+
await instance.addDocuments(docs);
|
|
155
|
+
return instance;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
exports.VoyVectorStore = VoyVectorStore;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import type { Voy as VoyOriginClient } from "voy-search";
|
|
2
|
+
import { Embeddings } from "../embeddings/base.js";
|
|
3
|
+
import { VectorStore } from "./base.js";
|
|
4
|
+
import { Document } from "../document.js";
|
|
5
|
+
export type VoyClient = Omit<VoyOriginClient, "remove" | "size" | "serialize" | "free">;
|
|
6
|
+
/**
|
|
7
|
+
* Internal interface for storing documents mappings.
|
|
8
|
+
*/
|
|
9
|
+
interface InternalDoc {
|
|
10
|
+
embeddings: number[];
|
|
11
|
+
document: Document;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Class that extends `VectorStore`. It allows to perform similarity search using
|
|
15
|
+
* Voi similarity search engine. The class requires passing Voy Client as an input parameter.
|
|
16
|
+
*/
|
|
17
|
+
export declare class VoyVectorStore extends VectorStore {
|
|
18
|
+
client: VoyClient;
|
|
19
|
+
numDimensions: number | null;
|
|
20
|
+
docstore: InternalDoc[];
|
|
21
|
+
_vectorstoreType(): string;
|
|
22
|
+
constructor(client: VoyClient, embeddings: Embeddings);
|
|
23
|
+
/**
|
|
24
|
+
* Adds documents to the Voy database. The documents are embedded using embeddings provided while instantiating the class.
|
|
25
|
+
* @param documents An array of `Document` instances associated with the vectors.
|
|
26
|
+
*/
|
|
27
|
+
addDocuments(documents: Document[]): Promise<void>;
|
|
28
|
+
/**
|
|
29
|
+
* Adds vectors to the Voy database. The vectors are associated with
|
|
30
|
+
* the provided documents.
|
|
31
|
+
* @param vectors An array of vectors to be added to the database.
|
|
32
|
+
* @param documents An array of `Document` instances associated with the vectors.
|
|
33
|
+
*/
|
|
34
|
+
addVectors(vectors: number[][], documents: Document[]): Promise<void>;
|
|
35
|
+
/**
|
|
36
|
+
* Searches for vectors in the Voy database that are similar to the
|
|
37
|
+
* provided query vector.
|
|
38
|
+
* @param query The query vector.
|
|
39
|
+
* @param k The number of similar vectors to return.
|
|
40
|
+
* @returns A promise that resolves with an array of tuples, each containing a `Document` instance and a similarity score.
|
|
41
|
+
*/
|
|
42
|
+
similaritySearchVectorWithScore(query: number[], k: number): Promise<[Document<Record<string, any>>, number][]>;
|
|
43
|
+
/**
|
|
44
|
+
* Method to delete data from the Voy index. It can delete data based
|
|
45
|
+
* on specific IDs or a filter.
|
|
46
|
+
* @param params Object that includes either an array of IDs or a filter for the data to be deleted.
|
|
47
|
+
* @returns Promise that resolves when the deletion is complete.
|
|
48
|
+
*/
|
|
49
|
+
delete(params: {
|
|
50
|
+
deleteAll?: boolean;
|
|
51
|
+
}): Promise<void>;
|
|
52
|
+
/**
|
|
53
|
+
* Creates a new `VoyVectorStore` instance from an array of text strings. The text
|
|
54
|
+
* strings are converted to `Document` instances and added to the Voy
|
|
55
|
+
* database.
|
|
56
|
+
* @param texts An array of text strings.
|
|
57
|
+
* @param metadatas An array of metadata objects or a single metadata object. If an array is provided, it must have the same length as the `texts` array.
|
|
58
|
+
* @param embeddings An `Embeddings` instance used to generate embeddings for the documents.
|
|
59
|
+
* @param client An instance of Voy client to use in the underlying operations.
|
|
60
|
+
* @returns A promise that resolves with a new `VoyVectorStore` instance.
|
|
61
|
+
*/
|
|
62
|
+
static fromTexts(texts: string[], metadatas: object[] | object, embeddings: Embeddings, client: VoyClient): Promise<VoyVectorStore>;
|
|
63
|
+
/**
|
|
64
|
+
* Creates a new `VoyVectorStore` instance from an array of `Document` instances.
|
|
65
|
+
* The documents are added to the Voy database.
|
|
66
|
+
* @param docs An array of `Document` instances.
|
|
67
|
+
* @param embeddings An `Embeddings` instance used to generate embeddings for the documents.
|
|
68
|
+
* @param client An instance of Voy client to use in the underlying operations.
|
|
69
|
+
* @returns A promise that resolves with a new `VoyVectorStore` instance.
|
|
70
|
+
*/
|
|
71
|
+
static fromDocuments(docs: Document[], embeddings: Embeddings, client: VoyClient): Promise<VoyVectorStore>;
|
|
72
|
+
}
|
|
73
|
+
export {};
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { VectorStore } from "./base.js";
|
|
2
|
+
import { Document } from "../document.js";
|
|
3
|
+
/**
|
|
4
|
+
* Class that extends `VectorStore`. It allows to perform similarity search using
|
|
5
|
+
* Voi similarity search engine. The class requires passing Voy Client as an input parameter.
|
|
6
|
+
*/
|
|
7
|
+
export class VoyVectorStore extends VectorStore {
|
|
8
|
+
_vectorstoreType() {
|
|
9
|
+
return "voi";
|
|
10
|
+
}
|
|
11
|
+
constructor(client, embeddings) {
|
|
12
|
+
super(embeddings, {});
|
|
13
|
+
Object.defineProperty(this, "client", {
|
|
14
|
+
enumerable: true,
|
|
15
|
+
configurable: true,
|
|
16
|
+
writable: true,
|
|
17
|
+
value: void 0
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(this, "numDimensions", {
|
|
20
|
+
enumerable: true,
|
|
21
|
+
configurable: true,
|
|
22
|
+
writable: true,
|
|
23
|
+
value: null
|
|
24
|
+
});
|
|
25
|
+
Object.defineProperty(this, "docstore", {
|
|
26
|
+
enumerable: true,
|
|
27
|
+
configurable: true,
|
|
28
|
+
writable: true,
|
|
29
|
+
value: []
|
|
30
|
+
});
|
|
31
|
+
this.client = client;
|
|
32
|
+
this.embeddings = embeddings;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Adds documents to the Voy database. The documents are embedded using embeddings provided while instantiating the class.
|
|
36
|
+
* @param documents An array of `Document` instances associated with the vectors.
|
|
37
|
+
*/
|
|
38
|
+
async addDocuments(documents) {
|
|
39
|
+
const texts = documents.map(({ pageContent }) => pageContent);
|
|
40
|
+
if (documents.length === 0) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
const firstVector = (await this.embeddings.embedDocuments(texts.slice(0, 1)))[0];
|
|
44
|
+
if (this.numDimensions === null) {
|
|
45
|
+
this.numDimensions = firstVector.length;
|
|
46
|
+
}
|
|
47
|
+
else if (this.numDimensions !== firstVector.length) {
|
|
48
|
+
throw new Error(`Vectors must have the same length as the number of dimensions (${this.numDimensions})`);
|
|
49
|
+
}
|
|
50
|
+
const restResults = await this.embeddings.embedDocuments(texts.slice(1));
|
|
51
|
+
await this.addVectors([firstVector, ...restResults], documents);
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Adds vectors to the Voy database. The vectors are associated with
|
|
55
|
+
* the provided documents.
|
|
56
|
+
* @param vectors An array of vectors to be added to the database.
|
|
57
|
+
* @param documents An array of `Document` instances associated with the vectors.
|
|
58
|
+
*/
|
|
59
|
+
async addVectors(vectors, documents) {
|
|
60
|
+
if (vectors.length === 0) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
if (this.numDimensions === null) {
|
|
64
|
+
this.numDimensions = vectors[0].length;
|
|
65
|
+
}
|
|
66
|
+
if (vectors.length !== documents.length) {
|
|
67
|
+
throw new Error(`Vectors and metadata must have the same length`);
|
|
68
|
+
}
|
|
69
|
+
if (!vectors.every((v) => v.length === this.numDimensions)) {
|
|
70
|
+
throw new Error(`Vectors must have the same length as the number of dimensions (${this.numDimensions})`);
|
|
71
|
+
}
|
|
72
|
+
vectors.forEach((item, idx) => {
|
|
73
|
+
const doc = documents[idx];
|
|
74
|
+
this.docstore.push({ embeddings: item, document: doc });
|
|
75
|
+
});
|
|
76
|
+
const embeddings = this.docstore.map((item, idx) => ({
|
|
77
|
+
id: String(idx),
|
|
78
|
+
embeddings: item.embeddings,
|
|
79
|
+
title: "",
|
|
80
|
+
url: "",
|
|
81
|
+
}));
|
|
82
|
+
this.client.index({ embeddings });
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Searches for vectors in the Voy database that are similar to the
|
|
86
|
+
* provided query vector.
|
|
87
|
+
* @param query The query vector.
|
|
88
|
+
* @param k The number of similar vectors to return.
|
|
89
|
+
* @returns A promise that resolves with an array of tuples, each containing a `Document` instance and a similarity score.
|
|
90
|
+
*/
|
|
91
|
+
async similaritySearchVectorWithScore(query, k) {
|
|
92
|
+
if (this.numDimensions === null) {
|
|
93
|
+
throw new Error("There aren't any elements in the index yet.");
|
|
94
|
+
}
|
|
95
|
+
if (query.length !== this.numDimensions) {
|
|
96
|
+
throw new Error(`Query vector must have the same length as the number of dimensions (${this.numDimensions})`);
|
|
97
|
+
}
|
|
98
|
+
const itemsToQuery = Math.min(this.docstore.length, k);
|
|
99
|
+
if (itemsToQuery > this.docstore.length) {
|
|
100
|
+
console.warn(`k (${k}) is greater than the number of elements in the index (${this.docstore.length}), setting k to ${itemsToQuery}`);
|
|
101
|
+
}
|
|
102
|
+
const results = this.client.search(new Float32Array(query), itemsToQuery);
|
|
103
|
+
return results.neighbors.map(({ id }, idx) => [this.docstore[parseInt(id, 10)].document, idx]);
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Method to delete data from the Voy index. It can delete data based
|
|
107
|
+
* on specific IDs or a filter.
|
|
108
|
+
* @param params Object that includes either an array of IDs or a filter for the data to be deleted.
|
|
109
|
+
* @returns Promise that resolves when the deletion is complete.
|
|
110
|
+
*/
|
|
111
|
+
async delete(params) {
|
|
112
|
+
if (params.deleteAll === true) {
|
|
113
|
+
await this.client.clear();
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
throw new Error(`You must provide a "deleteAll" parameter.`);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Creates a new `VoyVectorStore` instance from an array of text strings. The text
|
|
121
|
+
* strings are converted to `Document` instances and added to the Voy
|
|
122
|
+
* database.
|
|
123
|
+
* @param texts An array of text strings.
|
|
124
|
+
* @param metadatas An array of metadata objects or a single metadata object. If an array is provided, it must have the same length as the `texts` array.
|
|
125
|
+
* @param embeddings An `Embeddings` instance used to generate embeddings for the documents.
|
|
126
|
+
* @param client An instance of Voy client to use in the underlying operations.
|
|
127
|
+
* @returns A promise that resolves with a new `VoyVectorStore` instance.
|
|
128
|
+
*/
|
|
129
|
+
static async fromTexts(texts, metadatas, embeddings, client) {
|
|
130
|
+
const docs = [];
|
|
131
|
+
for (let i = 0; i < texts.length; i += 1) {
|
|
132
|
+
const metadata = Array.isArray(metadatas) ? metadatas[i] : metadatas;
|
|
133
|
+
const newDoc = new Document({
|
|
134
|
+
pageContent: texts[i],
|
|
135
|
+
metadata,
|
|
136
|
+
});
|
|
137
|
+
docs.push(newDoc);
|
|
138
|
+
}
|
|
139
|
+
return VoyVectorStore.fromDocuments(docs, embeddings, client);
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Creates a new `VoyVectorStore` instance from an array of `Document` instances.
|
|
143
|
+
* The documents are added to the Voy database.
|
|
144
|
+
* @param docs An array of `Document` instances.
|
|
145
|
+
* @param embeddings An `Embeddings` instance used to generate embeddings for the documents.
|
|
146
|
+
* @param client An instance of Voy client to use in the underlying operations.
|
|
147
|
+
* @returns A promise that resolves with a new `VoyVectorStore` instance.
|
|
148
|
+
*/
|
|
149
|
+
static async fromDocuments(docs, embeddings, client) {
|
|
150
|
+
const instance = new VoyVectorStore(client, embeddings);
|
|
151
|
+
await instance.addDocuments(docs);
|
|
152
|
+
return instance;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('../dist/embeddings/ollama.cjs');
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../dist/embeddings/ollama.js'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../dist/embeddings/ollama.js'
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "langchain",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.146",
|
|
4
4
|
"description": "Typescript bindings for langchain",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -70,9 +70,6 @@
|
|
|
70
70
|
"chains/sql_db.cjs",
|
|
71
71
|
"chains/sql_db.js",
|
|
72
72
|
"chains/sql_db.d.ts",
|
|
73
|
-
"embeddings.cjs",
|
|
74
|
-
"embeddings.js",
|
|
75
|
-
"embeddings.d.ts",
|
|
76
73
|
"embeddings/base.cjs",
|
|
77
74
|
"embeddings/base.js",
|
|
78
75
|
"embeddings/base.d.ts",
|
|
@@ -82,6 +79,9 @@
|
|
|
82
79
|
"embeddings/fake.cjs",
|
|
83
80
|
"embeddings/fake.js",
|
|
84
81
|
"embeddings/fake.d.ts",
|
|
82
|
+
"embeddings/ollama.cjs",
|
|
83
|
+
"embeddings/ollama.js",
|
|
84
|
+
"embeddings/ollama.d.ts",
|
|
85
85
|
"embeddings/openai.cjs",
|
|
86
86
|
"embeddings/openai.js",
|
|
87
87
|
"embeddings/openai.d.ts",
|
|
@@ -106,9 +106,6 @@
|
|
|
106
106
|
"embeddings/minimax.cjs",
|
|
107
107
|
"embeddings/minimax.js",
|
|
108
108
|
"embeddings/minimax.d.ts",
|
|
109
|
-
"llms.cjs",
|
|
110
|
-
"llms.js",
|
|
111
|
-
"llms.d.ts",
|
|
112
109
|
"llms/load.cjs",
|
|
113
110
|
"llms/load.js",
|
|
114
111
|
"llms/load.d.ts",
|
|
@@ -163,9 +160,6 @@
|
|
|
163
160
|
"prompts/load.cjs",
|
|
164
161
|
"prompts/load.js",
|
|
165
162
|
"prompts/load.d.ts",
|
|
166
|
-
"vectorstores.cjs",
|
|
167
|
-
"vectorstores.js",
|
|
168
|
-
"vectorstores.d.ts",
|
|
169
163
|
"vectorstores/analyticdb.cjs",
|
|
170
164
|
"vectorstores/analyticdb.js",
|
|
171
165
|
"vectorstores/analyticdb.d.ts",
|
|
@@ -244,6 +238,9 @@
|
|
|
244
238
|
"vectorstores/vectara.cjs",
|
|
245
239
|
"vectorstores/vectara.js",
|
|
246
240
|
"vectorstores/vectara.d.ts",
|
|
241
|
+
"vectorstores/voy.cjs",
|
|
242
|
+
"vectorstores/voy.js",
|
|
243
|
+
"vectorstores/voy.d.ts",
|
|
247
244
|
"vectorstores/xata.cjs",
|
|
248
245
|
"vectorstores/xata.js",
|
|
249
246
|
"vectorstores/xata.d.ts",
|
|
@@ -262,9 +259,6 @@
|
|
|
262
259
|
"document.cjs",
|
|
263
260
|
"document.js",
|
|
264
261
|
"document.d.ts",
|
|
265
|
-
"document_loaders.cjs",
|
|
266
|
-
"document_loaders.js",
|
|
267
|
-
"document_loaders.d.ts",
|
|
268
262
|
"document_loaders/base.cjs",
|
|
269
263
|
"document_loaders/base.js",
|
|
270
264
|
"document_loaders/base.d.ts",
|
|
@@ -379,9 +373,6 @@
|
|
|
379
373
|
"document_transformers/openai_functions.cjs",
|
|
380
374
|
"document_transformers/openai_functions.js",
|
|
381
375
|
"document_transformers/openai_functions.d.ts",
|
|
382
|
-
"chat_models.cjs",
|
|
383
|
-
"chat_models.js",
|
|
384
|
-
"chat_models.d.ts",
|
|
385
376
|
"chat_models/base.cjs",
|
|
386
377
|
"chat_models/base.js",
|
|
387
378
|
"chat_models/base.d.ts",
|
|
@@ -442,9 +433,6 @@
|
|
|
442
433
|
"output_parsers/expression.cjs",
|
|
443
434
|
"output_parsers/expression.js",
|
|
444
435
|
"output_parsers/expression.d.ts",
|
|
445
|
-
"retrievers.cjs",
|
|
446
|
-
"retrievers.js",
|
|
447
|
-
"retrievers.d.ts",
|
|
448
436
|
"retrievers/amazon_kendra.cjs",
|
|
449
437
|
"retrievers/amazon_kendra.js",
|
|
450
438
|
"retrievers/amazon_kendra.d.ts",
|
|
@@ -617,9 +605,9 @@
|
|
|
617
605
|
"clean": "rimraf dist/ && node scripts/create-entrypoints.js pre",
|
|
618
606
|
"prepack": "yarn build",
|
|
619
607
|
"release": "release-it --only-version --config .release-it.json",
|
|
620
|
-
"test": "NODE_OPTIONS=--experimental-vm-modules jest --testPathIgnorePatterns=\\.int\\.test.ts --testTimeout 30000",
|
|
608
|
+
"test": "NODE_OPTIONS=--experimental-vm-modules jest --testPathIgnorePatterns=\\.int\\.test.ts --testTimeout 30000 --maxWorkers=50%",
|
|
621
609
|
"test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch --testPathIgnorePatterns=\\.int\\.test.ts",
|
|
622
|
-
"test:integration": "NODE_OPTIONS=--experimental-vm-modules jest --testPathPattern=\\.int\\.test.ts --testTimeout 100000",
|
|
610
|
+
"test:integration": "NODE_OPTIONS=--experimental-vm-modules jest --testPathPattern=\\.int\\.test.ts --testTimeout 100000 --maxWorkers=50%",
|
|
623
611
|
"test:single": "NODE_OPTIONS=--experimental-vm-modules yarn run jest --config jest.config.cjs --testTimeout 100000",
|
|
624
612
|
"format": "prettier --write \"src\"",
|
|
625
613
|
"format:check": "prettier --check \"src\""
|
|
@@ -661,9 +649,9 @@
|
|
|
661
649
|
"@supabase/postgrest-js": "^1.1.1",
|
|
662
650
|
"@supabase/supabase-js": "^2.10.0",
|
|
663
651
|
"@tensorflow-models/universal-sentence-encoder": "^1.3.3",
|
|
664
|
-
"@tensorflow/tfjs-backend-cpu": "^
|
|
665
|
-
"@tensorflow/tfjs-converter": "^
|
|
666
|
-
"@tensorflow/tfjs-core": "^
|
|
652
|
+
"@tensorflow/tfjs-backend-cpu": "^3",
|
|
653
|
+
"@tensorflow/tfjs-converter": "^3.6.0",
|
|
654
|
+
"@tensorflow/tfjs-core": "^3.6.0",
|
|
667
655
|
"@tsconfig/recommended": "^1.0.2",
|
|
668
656
|
"@types/d3-dsv": "^2",
|
|
669
657
|
"@types/decamelize": "^1.2.0",
|
|
@@ -688,7 +676,7 @@
|
|
|
688
676
|
"axios": "^0.26.0",
|
|
689
677
|
"cheerio": "^1.0.0-rc.12",
|
|
690
678
|
"chromadb": "^1.5.3",
|
|
691
|
-
"cohere-ai": "
|
|
679
|
+
"cohere-ai": ">=6.0.0",
|
|
692
680
|
"d3-dsv": "^2.0.0",
|
|
693
681
|
"dotenv": "^16.0.3",
|
|
694
682
|
"dpdm": "^3.12.0",
|
|
@@ -740,6 +728,7 @@
|
|
|
740
728
|
"typesense": "^1.5.3",
|
|
741
729
|
"usearch": "^1.1.1",
|
|
742
730
|
"vectordb": "^0.1.4",
|
|
731
|
+
"voy-search": "0.6.2",
|
|
743
732
|
"weaviate-ts-client": "^1.4.0",
|
|
744
733
|
"youtube-transcript": "^1.0.6",
|
|
745
734
|
"youtubei.js": "^5.8.0"
|
|
@@ -786,8 +775,8 @@
|
|
|
786
775
|
"apify-client": "^2.7.1",
|
|
787
776
|
"axios": "*",
|
|
788
777
|
"cheerio": "^1.0.0-rc.12",
|
|
789
|
-
"chromadb": "
|
|
790
|
-
"cohere-ai": "
|
|
778
|
+
"chromadb": "*",
|
|
779
|
+
"cohere-ai": ">=6.0.0",
|
|
791
780
|
"d3-dsv": "^2.0.0",
|
|
792
781
|
"epub2": "^3.0.1",
|
|
793
782
|
"faiss-node": "^0.3.0",
|
|
@@ -799,7 +788,7 @@
|
|
|
799
788
|
"ignore": "^5.2.0",
|
|
800
789
|
"ioredis": "^5.3.2",
|
|
801
790
|
"jsdom": "*",
|
|
802
|
-
"llmonitor": "
|
|
791
|
+
"llmonitor": "*",
|
|
803
792
|
"mammoth": "*",
|
|
804
793
|
"mongodb": "^5.2.0",
|
|
805
794
|
"mysql2": "^3.3.3",
|
|
@@ -820,6 +809,7 @@
|
|
|
820
809
|
"typesense": "^1.5.3",
|
|
821
810
|
"usearch": "^1.1.1",
|
|
822
811
|
"vectordb": "^0.1.4",
|
|
812
|
+
"voy-search": "0.6.2",
|
|
823
813
|
"weaviate-ts-client": "^1.4.0",
|
|
824
814
|
"youtube-transcript": "^1.0.6",
|
|
825
815
|
"youtubei.js": "^5.8.0"
|
|
@@ -1050,6 +1040,9 @@
|
|
|
1050
1040
|
"vectordb": {
|
|
1051
1041
|
"optional": true
|
|
1052
1042
|
},
|
|
1043
|
+
"voy-search": {
|
|
1044
|
+
"optional": true
|
|
1045
|
+
},
|
|
1053
1046
|
"weaviate-ts-client": {
|
|
1054
1047
|
"optional": true
|
|
1055
1048
|
},
|
|
@@ -1075,7 +1068,7 @@
|
|
|
1075
1068
|
"langsmith": "~0.0.31",
|
|
1076
1069
|
"ml-distance": "^4.0.0",
|
|
1077
1070
|
"object-hash": "^3.0.0",
|
|
1078
|
-
"openai": "
|
|
1071
|
+
"openai": "~4.4.0",
|
|
1079
1072
|
"openapi-types": "^12.1.3",
|
|
1080
1073
|
"p-queue": "^6.6.2",
|
|
1081
1074
|
"p-retry": "4",
|
|
@@ -1102,11 +1095,6 @@
|
|
|
1102
1095
|
"vectorstores"
|
|
1103
1096
|
],
|
|
1104
1097
|
"exports": {
|
|
1105
|
-
".": {
|
|
1106
|
-
"types": "./index.d.ts",
|
|
1107
|
-
"import": "./index.js",
|
|
1108
|
-
"require": "./index.cjs"
|
|
1109
|
-
},
|
|
1110
1098
|
"./load": {
|
|
1111
1099
|
"types": "./load.d.ts",
|
|
1112
1100
|
"import": "./load.js",
|
|
@@ -1207,13 +1195,6 @@
|
|
|
1207
1195
|
"import": "./chains/sql_db.js",
|
|
1208
1196
|
"require": "./chains/sql_db.cjs"
|
|
1209
1197
|
},
|
|
1210
|
-
"./embeddings": {
|
|
1211
|
-
"node": {
|
|
1212
|
-
"types": "./embeddings.d.ts",
|
|
1213
|
-
"import": "./embeddings.js",
|
|
1214
|
-
"require": "./embeddings.cjs"
|
|
1215
|
-
}
|
|
1216
|
-
},
|
|
1217
1198
|
"./embeddings/base": {
|
|
1218
1199
|
"types": "./embeddings/base.d.ts",
|
|
1219
1200
|
"import": "./embeddings/base.js",
|
|
@@ -1229,6 +1210,11 @@
|
|
|
1229
1210
|
"import": "./embeddings/fake.js",
|
|
1230
1211
|
"require": "./embeddings/fake.cjs"
|
|
1231
1212
|
},
|
|
1213
|
+
"./embeddings/ollama": {
|
|
1214
|
+
"types": "./embeddings/ollama.d.ts",
|
|
1215
|
+
"import": "./embeddings/ollama.js",
|
|
1216
|
+
"require": "./embeddings/ollama.cjs"
|
|
1217
|
+
},
|
|
1232
1218
|
"./embeddings/openai": {
|
|
1233
1219
|
"types": "./embeddings/openai.d.ts",
|
|
1234
1220
|
"import": "./embeddings/openai.js",
|
|
@@ -1269,13 +1255,6 @@
|
|
|
1269
1255
|
"import": "./embeddings/minimax.js",
|
|
1270
1256
|
"require": "./embeddings/minimax.cjs"
|
|
1271
1257
|
},
|
|
1272
|
-
"./llms": {
|
|
1273
|
-
"node": {
|
|
1274
|
-
"types": "./llms.d.ts",
|
|
1275
|
-
"import": "./llms.js",
|
|
1276
|
-
"require": "./llms.cjs"
|
|
1277
|
-
}
|
|
1278
|
-
},
|
|
1279
1258
|
"./llms/load": {
|
|
1280
1259
|
"types": "./llms/load.d.ts",
|
|
1281
1260
|
"import": "./llms/load.js",
|
|
@@ -1366,13 +1345,6 @@
|
|
|
1366
1345
|
"import": "./prompts/load.js",
|
|
1367
1346
|
"require": "./prompts/load.cjs"
|
|
1368
1347
|
},
|
|
1369
|
-
"./vectorstores": {
|
|
1370
|
-
"node": {
|
|
1371
|
-
"types": "./vectorstores.d.ts",
|
|
1372
|
-
"import": "./vectorstores.js",
|
|
1373
|
-
"require": "./vectorstores.cjs"
|
|
1374
|
-
}
|
|
1375
|
-
},
|
|
1376
1348
|
"./vectorstores/analyticdb": {
|
|
1377
1349
|
"types": "./vectorstores/analyticdb.d.ts",
|
|
1378
1350
|
"import": "./vectorstores/analyticdb.js",
|
|
@@ -1503,6 +1475,11 @@
|
|
|
1503
1475
|
"import": "./vectorstores/vectara.js",
|
|
1504
1476
|
"require": "./vectorstores/vectara.cjs"
|
|
1505
1477
|
},
|
|
1478
|
+
"./vectorstores/voy": {
|
|
1479
|
+
"types": "./vectorstores/voy.d.ts",
|
|
1480
|
+
"import": "./vectorstores/voy.js",
|
|
1481
|
+
"require": "./vectorstores/voy.cjs"
|
|
1482
|
+
},
|
|
1506
1483
|
"./vectorstores/xata": {
|
|
1507
1484
|
"types": "./vectorstores/xata.d.ts",
|
|
1508
1485
|
"import": "./vectorstores/xata.js",
|
|
@@ -1533,13 +1510,6 @@
|
|
|
1533
1510
|
"import": "./document.js",
|
|
1534
1511
|
"require": "./document.cjs"
|
|
1535
1512
|
},
|
|
1536
|
-
"./document_loaders": {
|
|
1537
|
-
"node": {
|
|
1538
|
-
"types": "./document_loaders.d.ts",
|
|
1539
|
-
"import": "./document_loaders.js",
|
|
1540
|
-
"require": "./document_loaders.cjs"
|
|
1541
|
-
}
|
|
1542
|
-
},
|
|
1543
1513
|
"./document_loaders/base": {
|
|
1544
1514
|
"types": "./document_loaders/base.d.ts",
|
|
1545
1515
|
"import": "./document_loaders/base.js",
|
|
@@ -1730,13 +1700,6 @@
|
|
|
1730
1700
|
"import": "./document_transformers/openai_functions.js",
|
|
1731
1701
|
"require": "./document_transformers/openai_functions.cjs"
|
|
1732
1702
|
},
|
|
1733
|
-
"./chat_models": {
|
|
1734
|
-
"node": {
|
|
1735
|
-
"types": "./chat_models.d.ts",
|
|
1736
|
-
"import": "./chat_models.js",
|
|
1737
|
-
"require": "./chat_models.cjs"
|
|
1738
|
-
}
|
|
1739
|
-
},
|
|
1740
1703
|
"./chat_models/base": {
|
|
1741
1704
|
"types": "./chat_models/base.d.ts",
|
|
1742
1705
|
"import": "./chat_models/base.js",
|
|
@@ -1837,13 +1800,6 @@
|
|
|
1837
1800
|
"import": "./output_parsers/expression.js",
|
|
1838
1801
|
"require": "./output_parsers/expression.cjs"
|
|
1839
1802
|
},
|
|
1840
|
-
"./retrievers": {
|
|
1841
|
-
"node": {
|
|
1842
|
-
"types": "./retrievers.d.ts",
|
|
1843
|
-
"import": "./retrievers.js",
|
|
1844
|
-
"require": "./retrievers.cjs"
|
|
1845
|
-
}
|
|
1846
|
-
},
|
|
1847
1803
|
"./retrievers/amazon_kendra": {
|
|
1848
1804
|
"types": "./retrievers/amazon_kendra.d.ts",
|
|
1849
1805
|
"import": "./retrievers/amazon_kendra.js",
|