mirror of
https://github.com/run-llama/LlamaIndexTS.git
synced 2026-07-11 00:04:07 -04:00
feat: Add MongoDB driver metadata (#2240)
Co-authored-by: Marcus Schiesser <mail@marcusschiesser.de>
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
---
|
||||
"@llamaindex/mongodb": minor
|
||||
"@llamaindex/azure": minor
|
||||
"@llamaindex/tools": minor
|
||||
"@llamaindex/examples": minor
|
||||
---
|
||||
|
||||
Update storage providers to append MongoDB client metadata
|
||||
@@ -67,7 +67,7 @@
|
||||
"dotenv": "^17.2.0",
|
||||
"js-tiktoken": "^1.0.14",
|
||||
"llamaindex": "^0.12.0",
|
||||
"mongodb": "6.7.0",
|
||||
"mongodb": "6.21.0",
|
||||
"postgres": "^3.4.4",
|
||||
"wikipedia": "^2.1.2",
|
||||
"zod": "^4.1.5"
|
||||
|
||||
@@ -72,7 +72,7 @@
|
||||
"@azure/identity": "^4.4.1",
|
||||
"@azure/search-documents": "^12.1.0",
|
||||
"@llamaindex/openai": "workspace:*",
|
||||
"mongodb": "^6.7.0",
|
||||
"mongodb": "^6.21.0",
|
||||
"openai": "^4.90.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,8 @@ import type {
|
||||
import { BaseChatStore } from "@llamaindex/core/storage/chat-store";
|
||||
import type { Collection } from "mongodb";
|
||||
import { MongoClient } from "mongodb";
|
||||
import pkg from "../../package.json";
|
||||
|
||||
const DEFAULT_CHAT_DATABASE = "ChatStoreDB";
|
||||
const DEFAULT_CHAT_Collection = "ChatStoreCollection";
|
||||
|
||||
@@ -40,6 +42,10 @@ export class AzureCosmosVCoreChatStore<
|
||||
"MongoClient is required for AzureCosmosVCoreChatStore initialization",
|
||||
);
|
||||
}
|
||||
mongoClient.appendMetadata({
|
||||
name: "LLAMAINDEX_AZURE_COSMOS_VCORE_CHAT_STORE",
|
||||
version: pkg.version,
|
||||
});
|
||||
this.mongoClient = mongoClient;
|
||||
this.dbName = dbName;
|
||||
this.collectionName = collectionName;
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
import { BaseKVStore } from "@llamaindex/core/storage/kv-store";
|
||||
import type { Collection } from "mongodb";
|
||||
import { MongoClient } from "mongodb";
|
||||
import pkg from "../../package.json";
|
||||
const DEFAULT_CHAT_DATABASE = "KVStoreDB";
|
||||
const DEFAULT_CHAT_Collection = "KVStoreCollection";
|
||||
|
||||
@@ -38,6 +39,10 @@ export class AzureCosmosVCoreKVStore extends BaseKVStore {
|
||||
"MongoClient is required for AzureCosmosDBNoSQLVectorStore initialization",
|
||||
);
|
||||
}
|
||||
mongoClient.appendMetadata({
|
||||
name: "LLAMAINDEX_AZURE_COSMOS_VCORE_KV_STORE",
|
||||
version: pkg.version,
|
||||
});
|
||||
this.mongoClient = mongoClient;
|
||||
this.dbName = dbName;
|
||||
this.collectionName = collectionName;
|
||||
|
||||
@@ -10,6 +10,7 @@ import {
|
||||
} from "@llamaindex/core/vector-store";
|
||||
import { getEnv } from "@llamaindex/env";
|
||||
import { Collection, Db, MongoClient } from "mongodb";
|
||||
import pkg from "../../package.json";
|
||||
|
||||
/** Azure Cosmos DB for MongoDB vCore Similarity type. */
|
||||
export const AzureCosmosDBMongoDBSimilarityType = {
|
||||
@@ -124,6 +125,10 @@ export class AzureCosmosDBMongoDBVectorStore extends BaseVectorStore {
|
||||
appName: "LLAMAINDEX_JS",
|
||||
});
|
||||
}
|
||||
this.mongodbClient.appendMetadata({
|
||||
name: "LLAMAINDEX_AZURE_COSMOS_VCORE_VECTOR_STORE",
|
||||
version: pkg.version,
|
||||
});
|
||||
|
||||
this.dbName = init.dbName ?? "documentsDB";
|
||||
this.collectionName = init.collectionName ?? "documents";
|
||||
|
||||
@@ -49,6 +49,6 @@
|
||||
"@llamaindex/env": "workspace:*"
|
||||
},
|
||||
"dependencies": {
|
||||
"mongodb": "6.7.0"
|
||||
"mongodb": "6.21.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ import {
|
||||
import { getEnv } from "@llamaindex/env";
|
||||
import type { BulkWriteOptions, Collection } from "mongodb";
|
||||
import { MongoClient } from "mongodb";
|
||||
import pkg from "../package.json";
|
||||
|
||||
// define your Atlas Search index. See detail https://www.mongodb.com/docs/atlas/atlas-search/field-types/knn-vector/
|
||||
const DEFAULT_EMBEDDING_DEFINITION = {
|
||||
@@ -162,6 +163,10 @@ export class MongoDBAtlasVectorSearch extends BaseVectorStore {
|
||||
|
||||
this.dbName = init.dbName ?? "default_db";
|
||||
this.collectionName = init.collectionName ?? "default_collection";
|
||||
this.mongodbClient.appendMetadata({
|
||||
name: "LLAMAINDEX_MONGODB_ATLAS_VECTOR_STORE",
|
||||
version: pkg.version,
|
||||
});
|
||||
this.autoCreateIndex = init.autoCreateIndex ?? true;
|
||||
this.indexedMetadataFields = init.indexedMetadataFields ?? [];
|
||||
this.embeddingDefinition = {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { KVDocumentStore } from "@llamaindex/core/storage/doc-store";
|
||||
import { MongoClient } from "mongodb";
|
||||
import pkg from "../../package.json";
|
||||
import { MongoKVStore } from "../kvStore/MongoKVStore";
|
||||
|
||||
const DEFAULT_DATABASE = "DocumentStoreDB";
|
||||
@@ -36,6 +37,10 @@ export class MongoDocumentStore extends KVDocumentStore {
|
||||
mongoClient,
|
||||
dbName,
|
||||
});
|
||||
mongoClient.appendMetadata({
|
||||
name: "LLAMAINDEX_MONGODB_DOC_STORE",
|
||||
version: pkg.version,
|
||||
});
|
||||
|
||||
return new MongoDocumentStore({
|
||||
mongoKVStore,
|
||||
|
||||
@@ -24,6 +24,9 @@ export class MongoKVStore extends BaseKVStore {
|
||||
|
||||
this.mongoClient = mongoClient;
|
||||
this.dbName = dbName;
|
||||
this.mongoClient.appendMetadata({
|
||||
name: "LLAMAINDEX_MONGODB_KV_STORE",
|
||||
});
|
||||
}
|
||||
|
||||
get client(): MongoClient {
|
||||
|
||||
@@ -1,6 +1,16 @@
|
||||
import { Document, MetadataMode } from "@llamaindex/core/schema";
|
||||
import { MongoClient } from "mongodb";
|
||||
import { afterAll, beforeAll, beforeEach, describe, expect, it } from "vitest";
|
||||
import { MongoClient, type DriverInfo } from "mongodb";
|
||||
import {
|
||||
afterAll,
|
||||
beforeAll,
|
||||
beforeEach,
|
||||
describe,
|
||||
expect,
|
||||
it,
|
||||
vi,
|
||||
type MockInstance,
|
||||
} from "vitest";
|
||||
import pkg from "../../package.json";
|
||||
import { MongoDocumentStore } from "../docStore/MongoDBDocumentStore";
|
||||
import { setupTestDb } from "./setuptTestDb";
|
||||
|
||||
@@ -9,11 +19,13 @@ describe("MongoDocumentStore", () => {
|
||||
let mongoClient: MongoClient;
|
||||
let documentStore: MongoDocumentStore;
|
||||
let mongoUri: string;
|
||||
let appendMetadataSpy: MockInstance<(driverInfo: DriverInfo) => void>;
|
||||
|
||||
beforeAll(async () => {
|
||||
const testDb = await setupTestDb();
|
||||
cleanup = testDb.cleanup;
|
||||
mongoClient = testDb.mongoClient;
|
||||
appendMetadataSpy = vi.spyOn(mongoClient, "appendMetadata");
|
||||
mongoUri = testDb.mongoUri;
|
||||
documentStore = MongoDocumentStore.fromMongoClient(mongoClient);
|
||||
}, 120000);
|
||||
@@ -26,6 +38,10 @@ describe("MongoDocumentStore", () => {
|
||||
it("should create instance with mongoClient", () => {
|
||||
const store = MongoDocumentStore.fromMongoClient(mongoClient);
|
||||
expect(store).toBeInstanceOf(MongoDocumentStore);
|
||||
expect(appendMetadataSpy).toHaveBeenCalledWith({
|
||||
name: "LLAMAINDEX_MONGODB_DOC_STORE",
|
||||
version: pkg.version,
|
||||
});
|
||||
});
|
||||
|
||||
it("should create instance with custom namespace", () => {
|
||||
@@ -35,6 +51,10 @@ describe("MongoDocumentStore", () => {
|
||||
"namespace",
|
||||
);
|
||||
expect(store).toBeInstanceOf(MongoDocumentStore);
|
||||
expect(appendMetadataSpy).toHaveBeenCalledWith({
|
||||
name: "LLAMAINDEX_MONGODB_DOC_STORE",
|
||||
version: pkg.version,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -47,6 +67,10 @@ describe("MongoDocumentStore", () => {
|
||||
it("should create instance from MongoClient", () => {
|
||||
const store = MongoDocumentStore.fromMongoClient(mongoClient);
|
||||
expect(store).toBeInstanceOf(MongoDocumentStore);
|
||||
expect(appendMetadataSpy).toHaveBeenCalledWith({
|
||||
name: "LLAMAINDEX_MONGODB_DOC_STORE",
|
||||
version: pkg.version,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -1,5 +1,14 @@
|
||||
import type { MongoClient } from "mongodb";
|
||||
import { afterAll, beforeAll, beforeEach, describe, expect, it } from "vitest";
|
||||
import type { DriverInfo, MongoClient } from "mongodb";
|
||||
import {
|
||||
afterAll,
|
||||
beforeAll,
|
||||
beforeEach,
|
||||
describe,
|
||||
expect,
|
||||
it,
|
||||
vi,
|
||||
type MockInstance,
|
||||
} from "vitest";
|
||||
import { MongoKVStore } from "../kvStore/MongoKVStore";
|
||||
import { setupTestDb } from "./setuptTestDb";
|
||||
|
||||
@@ -8,11 +17,13 @@ describe("MongoKVStore", () => {
|
||||
let mongoClient: MongoClient;
|
||||
let mongoUri: string;
|
||||
let kvStore: MongoKVStore;
|
||||
let appendMetadataSpy: MockInstance<(driverInfo: DriverInfo) => void>;
|
||||
|
||||
beforeAll(async () => {
|
||||
const testDb = await setupTestDb();
|
||||
cleanUp = testDb.cleanup;
|
||||
mongoClient = testDb.mongoClient;
|
||||
appendMetadataSpy = vi.spyOn(mongoClient, "appendMetadata");
|
||||
mongoUri = testDb.mongoUri;
|
||||
kvStore = new MongoKVStore({
|
||||
mongoClient,
|
||||
@@ -32,6 +43,9 @@ describe("MongoKVStore", () => {
|
||||
});
|
||||
|
||||
expect(kvStore).toBeInstanceOf(MongoKVStore);
|
||||
expect(appendMetadataSpy).toHaveBeenCalledWith({
|
||||
name: "LLAMAINDEX_MONGODB_KV_STORE",
|
||||
});
|
||||
});
|
||||
|
||||
it("should create db with custom db and collection name", () => {
|
||||
@@ -41,6 +55,9 @@ describe("MongoKVStore", () => {
|
||||
});
|
||||
|
||||
expect(kvStore).toBeInstanceOf(MongoKVStore);
|
||||
expect(appendMetadataSpy).toHaveBeenCalledWith({
|
||||
name: "LLAMAINDEX_MONGODB_KV_STORE",
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
"outDir": "./lib",
|
||||
"tsBuildInfoFile": "./lib/.tsbuildinfo"
|
||||
},
|
||||
"include": ["./src"],
|
||||
"include": ["./src", "package.json"],
|
||||
"references": [
|
||||
{
|
||||
"path": "../../../core/tsconfig.json"
|
||||
|
||||
Generated
+26
-49
@@ -523,8 +523,8 @@ importers:
|
||||
specifier: ^0.12.0
|
||||
version: link:../packages/llamaindex
|
||||
mongodb:
|
||||
specifier: 6.7.0
|
||||
version: 6.7.0(@aws-sdk/credential-providers@3.913.0)(socks@2.8.4)
|
||||
specifier: 6.21.0
|
||||
version: 6.21.0(@aws-sdk/credential-providers@3.913.0)(socks@2.8.4)
|
||||
postgres:
|
||||
specifier: ^3.4.4
|
||||
version: 3.4.5
|
||||
@@ -1269,8 +1269,8 @@ importers:
|
||||
specifier: workspace:*
|
||||
version: link:../../openai
|
||||
mongodb:
|
||||
specifier: ^6.7.0
|
||||
version: 6.7.0(@aws-sdk/credential-providers@3.913.0)(socks@2.8.4)
|
||||
specifier: ^6.21.0
|
||||
version: 6.21.0(@aws-sdk/credential-providers@3.913.0)(socks@2.8.4)
|
||||
openai:
|
||||
specifier: ^4.90.0
|
||||
version: 4.94.0(ws@8.18.1(bufferutil@4.0.9))(zod@3.25.76)
|
||||
@@ -1364,8 +1364,8 @@ importers:
|
||||
packages/providers/storage/mongodb:
|
||||
dependencies:
|
||||
mongodb:
|
||||
specifier: 6.7.0
|
||||
version: 6.7.0(@aws-sdk/credential-providers@3.913.0)(socks@2.8.4)
|
||||
specifier: 6.21.0
|
||||
version: 6.21.0(@aws-sdk/credential-providers@3.913.0)(socks@2.8.4)
|
||||
devDependencies:
|
||||
'@llamaindex/core':
|
||||
specifier: workspace:*
|
||||
@@ -3767,6 +3767,9 @@ packages:
|
||||
'@mongodb-js/saslprep@1.2.0':
|
||||
resolution: {integrity: sha512-+ywrb0AqkfaYuhHs6LxKWgqbh3I72EpEgESCw37o+9qPx9WTCkgDm2B+eMrwehGtHBWHFU4GXvnSCNiFhhausg==}
|
||||
|
||||
'@mongodb-js/saslprep@1.3.2':
|
||||
resolution: {integrity: sha512-QgA5AySqB27cGTXBFmnpifAi7HxoGUeezwo6p9dI03MuDB6Pp33zgclqVb6oVK3j6I9Vesg0+oojW2XxB59SGg==}
|
||||
|
||||
'@mswjs/interceptors@0.37.6':
|
||||
resolution: {integrity: sha512-wK+5pLK5XFmgtH3aQ2YVvA3HohS3xqV/OxuVOdNx9Wpnz7VE/fnC+e1A7ln6LFYeck7gOJ/dsZV6OLplOtAJ2w==}
|
||||
engines: {node: '>=18'}
|
||||
@@ -6329,6 +6332,10 @@ packages:
|
||||
resolution: {integrity: sha512-MTxGsqgYTwfshYWTRdmZRC+M7FnG1b4y7RO7p2k3X24Wq0yv1m77Wsj0BzlPzd/IowgESfsruQCUToa7vbOpPQ==}
|
||||
engines: {node: '>=16.20.1'}
|
||||
|
||||
bson@6.10.4:
|
||||
resolution: {integrity: sha512-WIsKqkSC0ABoBJuT1LEX+2HEvNmNKKgnTAyd0fL8qzK4SH2i9NXg+t08YtdZp/V9IZ33cxe3iV4yM0qg8lMQng==}
|
||||
engines: {node: '>=16.20.1'}
|
||||
|
||||
buffer-crc32@0.2.13:
|
||||
resolution: {integrity: sha512-VO9Ht/+p3SN7SKWqcrgEzjGbRSJYTx+Q1pTQC0wrWqHx0vpJraQ6GtHx8tvcg1rlK1byhU5gccxgOgj7B0TDkQ==}
|
||||
|
||||
@@ -8917,8 +8924,8 @@ packages:
|
||||
socks:
|
||||
optional: true
|
||||
|
||||
mongodb@6.15.0:
|
||||
resolution: {integrity: sha512-ifBhQ0rRzHDzqp9jAQP6OwHSH7dbYIQjD3SbJs9YYk9AikKEettW/9s/tbSFDTpXcRbF+u1aLrhHxDFaYtZpFQ==}
|
||||
mongodb@6.21.0:
|
||||
resolution: {integrity: sha512-URyb/VXMjJ4da46OeSXg+puO39XH9DeQpWCslifrRn9JWugy0D+DvvBvkm2WxmHe61O/H19JM66p1z7RHVkZ6A==}
|
||||
engines: {node: '>=16.20.1'}
|
||||
peerDependencies:
|
||||
'@aws-sdk/credential-providers': ^3.188.0
|
||||
@@ -8926,34 +8933,7 @@ packages:
|
||||
gcp-metadata: ^5.2.0
|
||||
kerberos: ^2.0.1
|
||||
mongodb-client-encryption: '>=6.0.0 <7'
|
||||
snappy: ^7.2.2
|
||||
socks: ^2.7.1
|
||||
peerDependenciesMeta:
|
||||
'@aws-sdk/credential-providers':
|
||||
optional: true
|
||||
'@mongodb-js/zstd':
|
||||
optional: true
|
||||
gcp-metadata:
|
||||
optional: true
|
||||
kerberos:
|
||||
optional: true
|
||||
mongodb-client-encryption:
|
||||
optional: true
|
||||
snappy:
|
||||
optional: true
|
||||
socks:
|
||||
optional: true
|
||||
|
||||
mongodb@6.7.0:
|
||||
resolution: {integrity: sha512-TMKyHdtMcO0fYBNORiYdmM25ijsHs+Njs963r4Tro4OQZzqYigAzYQouwWRg4OIaiLRUEGUh/1UAcH5lxdSLIA==}
|
||||
engines: {node: '>=16.20.1'}
|
||||
peerDependencies:
|
||||
'@aws-sdk/credential-providers': ^3.188.0
|
||||
'@mongodb-js/zstd': ^1.1.0
|
||||
gcp-metadata: ^5.2.0
|
||||
kerberos: ^2.0.1
|
||||
mongodb-client-encryption: '>=6.0.0 <7'
|
||||
snappy: ^7.2.2
|
||||
snappy: ^7.3.2
|
||||
socks: ^2.7.1
|
||||
peerDependenciesMeta:
|
||||
'@aws-sdk/credential-providers':
|
||||
@@ -14495,6 +14475,10 @@ snapshots:
|
||||
dependencies:
|
||||
sparse-bitfield: 3.0.3
|
||||
|
||||
'@mongodb-js/saslprep@1.3.2':
|
||||
dependencies:
|
||||
sparse-bitfield: 3.0.3
|
||||
|
||||
'@mswjs/interceptors@0.37.6':
|
||||
dependencies:
|
||||
'@open-draft/deferred-promise': 2.2.0
|
||||
@@ -17339,6 +17323,8 @@ snapshots:
|
||||
|
||||
bson@6.10.3: {}
|
||||
|
||||
bson@6.10.4: {}
|
||||
|
||||
buffer-crc32@0.2.13: {}
|
||||
|
||||
buffer-equal-constant-time@1.0.1: {}
|
||||
@@ -20300,7 +20286,7 @@ snapshots:
|
||||
find-cache-dir: 3.3.2
|
||||
follow-redirects: 1.15.9(debug@4.4.1)
|
||||
https-proxy-agent: 7.0.6
|
||||
mongodb: 6.15.0(@aws-sdk/credential-providers@3.913.0)(socks@2.8.4)
|
||||
mongodb: 6.21.0(@aws-sdk/credential-providers@3.913.0)(socks@2.8.4)
|
||||
new-find-package-json: 2.0.0
|
||||
semver: 7.7.1
|
||||
tar-stream: 3.1.7
|
||||
@@ -20339,19 +20325,10 @@ snapshots:
|
||||
'@aws-sdk/credential-providers': 3.913.0
|
||||
socks: 2.8.4
|
||||
|
||||
mongodb@6.15.0(@aws-sdk/credential-providers@3.913.0)(socks@2.8.4):
|
||||
mongodb@6.21.0(@aws-sdk/credential-providers@3.913.0)(socks@2.8.4):
|
||||
dependencies:
|
||||
'@mongodb-js/saslprep': 1.2.0
|
||||
bson: 6.10.3
|
||||
mongodb-connection-string-url: 3.0.2
|
||||
optionalDependencies:
|
||||
'@aws-sdk/credential-providers': 3.913.0
|
||||
socks: 2.8.4
|
||||
|
||||
mongodb@6.7.0(@aws-sdk/credential-providers@3.913.0)(socks@2.8.4):
|
||||
dependencies:
|
||||
'@mongodb-js/saslprep': 1.2.0
|
||||
bson: 6.10.3
|
||||
'@mongodb-js/saslprep': 1.3.2
|
||||
bson: 6.10.4
|
||||
mongodb-connection-string-url: 3.0.2
|
||||
optionalDependencies:
|
||||
'@aws-sdk/credential-providers': 3.913.0
|
||||
|
||||
Reference in New Issue
Block a user