Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .changeset/warm-pants-teach.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@llamaindex/mongodb": minor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this file accidentally committed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, not an accident. Changesets is how this project manages versioning.

Here's a similar PR we are working on, which also has a similar change: langchain-ai/langgraphjs#1777

"@llamaindex/azure": minor
"@llamaindex/tools": minor
"@llamaindex/examples": minor
---

Update storage providers to append MongoDB client metadata
2 changes: 1 addition & 1 deletion examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion packages/providers/storage/azure/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -40,6 +42,10 @@ export class AzureCosmosVCoreChatStore<
"MongoClient is required for AzureCosmosVCoreChatStore initialization",
);
}
mongoClient.appendMetadata({
name: "LLAMAINDEX_AZURE_COSMOS_VCORE_CHAT_STORE",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If possible, we try and include the package version. But it isn't always feasible because it usually requires reading the package.json file, which some codebases don't like (require('./package.json').version).

I suggest adding the packages versions and asking the team what they think.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea.
Looks like there's already some code that does this, will follow this approach: https://github.com/run-llama/LlamaIndexTS/blob/main/packages/providers/storage/azure/src/model/azure.ts#L153

version: pkg.version,
});
this.mongoClient = mongoClient;
this.dbName = dbName;
this.collectionName = collectionName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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";
Expand Down
2 changes: 1 addition & 1 deletion packages/providers/storage/mongodb/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,6 @@
"@llamaindex/env": "workspace:*"
},
"dependencies": {
"mongodb": "6.7.0"
"mongodb": "6.21.0"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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 = {
Expand Down
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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";

Expand All @@ -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);
Expand All @@ -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", () => {
Expand All @@ -35,6 +51,10 @@ describe("MongoDocumentStore", () => {
"namespace",
);
expect(store).toBeInstanceOf(MongoDocumentStore);
expect(appendMetadataSpy).toHaveBeenCalledWith({
name: "LLAMAINDEX_MONGODB_DOC_STORE",
version: pkg.version,
});
});
});

Expand All @@ -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,
});
});
});

Expand Down
21 changes: 19 additions & 2 deletions packages/providers/storage/mongodb/src/tests/MongokVStore.test.ts
Original file line number Diff line number Diff line change
@@ -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";

Expand All @@ -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,
Expand All @@ -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", () => {
Expand All @@ -41,6 +55,9 @@ describe("MongoKVStore", () => {
});

expect(kvStore).toBeInstanceOf(MongoKVStore);
expect(appendMetadataSpy).toHaveBeenCalledWith({
name: "LLAMAINDEX_MONGODB_KV_STORE",
});
});
});

Expand Down
2 changes: 1 addition & 1 deletion packages/providers/storage/mongodb/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"outDir": "./lib",
"tsBuildInfoFile": "./lib/.tsbuildinfo"
},
"include": ["./src"],
"include": ["./src", "package.json"],
"references": [
{
"path": "../../../core/tsconfig.json"
Expand Down
Loading
Loading