File tree 3 files changed +7
-3
lines changed
templates/components/vectordbs/typescript/mongo 3 files changed +7
-3
lines changed Original file line number Diff line number Diff line change 1
1
/* eslint-disable turbo/no-undeclared-env-vars */
2
2
import * as dotenv from "dotenv" ;
3
- import { VectorStoreIndex , storageContextFromDefaults } from "llamaindex" ;
3
+ import { storageContextFromDefaults , VectorStoreIndex } from "llamaindex" ;
4
4
import { MongoDBAtlasVectorSearch } from "llamaindex/storage/vectorStore/MongoDBAtlasVectorStore" ;
5
5
import { MongoClient } from "mongodb" ;
6
6
import { getDocuments } from "./loader" ;
7
7
import { initSettings } from "./settings" ;
8
- import { checkRequiredEnvVars } from "./shared" ;
8
+ import { checkRequiredEnvVars , POPULATED_METADATA_FIELDS } from "./shared" ;
9
9
10
10
dotenv . config ( ) ;
11
11
@@ -27,6 +27,7 @@ async function loadAndIndex() {
27
27
dbName : databaseName ,
28
28
collectionName : vectorCollectionName , // this is where your embeddings will be stored
29
29
indexName : indexName , // this is the name of the index you will need to create
30
+ populatedMetadataFields : POPULATED_METADATA_FIELDS ,
30
31
} ) ;
31
32
32
33
// now create an index from all the Documents and store them in Atlas
Original file line number Diff line number Diff line change 2
2
import { VectorStoreIndex } from "llamaindex" ;
3
3
import { MongoDBAtlasVectorSearch } from "llamaindex/storage/vectorStore/MongoDBAtlasVectorStore" ;
4
4
import { MongoClient } from "mongodb" ;
5
- import { checkRequiredEnvVars } from "./shared" ;
5
+ import { checkRequiredEnvVars , POPULATED_METADATA_FIELDS } from "./shared" ;
6
6
7
7
export async function getDataSource ( params ?: any ) {
8
8
checkRequiredEnvVars ( ) ;
@@ -12,6 +12,7 @@ export async function getDataSource(params?: any) {
12
12
dbName : process . env . MONGODB_DATABASE ! ,
13
13
collectionName : process . env . MONGODB_VECTORS ! ,
14
14
indexName : process . env . MONGODB_VECTOR_INDEX ,
15
+ populatedMetadataFields : POPULATED_METADATA_FIELDS ,
15
16
} ) ;
16
17
17
18
return await VectorStoreIndex . fromVectorStore ( store ) ;
Original file line number Diff line number Diff line change @@ -5,6 +5,8 @@ const REQUIRED_ENV_VARS = [
5
5
"MONGODB_VECTOR_INDEX" ,
6
6
] ;
7
7
8
+ export const POPULATED_METADATA_FIELDS = [ "private" , "doc_id" ] ; // for filtering in MongoDB VectorSearchIndex
9
+
8
10
export function checkRequiredEnvVars ( ) {
9
11
const missingEnvVars = REQUIRED_ENV_VARS . filter ( ( envVar ) => {
10
12
return ! process . env [ envVar ] ;
You can’t perform that action at this time.
0 commit comments