Skip to content

Commit a7d4d1c

Browse files
committed
update populate metadata fields
1 parent cf938ed commit a7d4d1c

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

templates/components/vectordbs/typescript/mongo/generate.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/* eslint-disable turbo/no-undeclared-env-vars */
22
import * as dotenv from "dotenv";
3-
import { VectorStoreIndex, storageContextFromDefaults } from "llamaindex";
3+
import { storageContextFromDefaults, VectorStoreIndex } from "llamaindex";
44
import { MongoDBAtlasVectorSearch } from "llamaindex/storage/vectorStore/MongoDBAtlasVectorStore";
55
import { MongoClient } from "mongodb";
66
import { getDocuments } from "./loader";
77
import { initSettings } from "./settings";
8-
import { checkRequiredEnvVars } from "./shared";
8+
import { checkRequiredEnvVars, POPULATED_METADATA_FIELDS } from "./shared";
99

1010
dotenv.config();
1111

@@ -27,6 +27,7 @@ async function loadAndIndex() {
2727
dbName: databaseName,
2828
collectionName: vectorCollectionName, // this is where your embeddings will be stored
2929
indexName: indexName, // this is the name of the index you will need to create
30+
populatedMetadataFields: POPULATED_METADATA_FIELDS,
3031
});
3132

3233
// now create an index from all the Documents and store them in Atlas

templates/components/vectordbs/typescript/mongo/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import { VectorStoreIndex } from "llamaindex";
33
import { MongoDBAtlasVectorSearch } from "llamaindex/storage/vectorStore/MongoDBAtlasVectorStore";
44
import { MongoClient } from "mongodb";
5-
import { checkRequiredEnvVars } from "./shared";
5+
import { checkRequiredEnvVars, POPULATED_METADATA_FIELDS } from "./shared";
66

77
export async function getDataSource(params?: any) {
88
checkRequiredEnvVars();
@@ -12,6 +12,7 @@ export async function getDataSource(params?: any) {
1212
dbName: process.env.MONGODB_DATABASE!,
1313
collectionName: process.env.MONGODB_VECTORS!,
1414
indexName: process.env.MONGODB_VECTOR_INDEX,
15+
populatedMetadataFields: POPULATED_METADATA_FIELDS,
1516
});
1617

1718
return await VectorStoreIndex.fromVectorStore(store);

templates/components/vectordbs/typescript/mongo/shared.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ const REQUIRED_ENV_VARS = [
55
"MONGODB_VECTOR_INDEX",
66
];
77

8+
export const POPULATED_METADATA_FIELDS = ["private", "doc_id"]; // for filtering in MongoDB VectorSearchIndex
9+
810
export function checkRequiredEnvVars() {
911
const missingEnvVars = REQUIRED_ENV_VARS.filter((envVar) => {
1012
return !process.env[envVar];

0 commit comments

Comments
 (0)