MongoDBQueryEngine
This engine initializes a vector database, builds an index from input documents, and allows querying using the chat engine interface.
Attributes:
vector_db (MongoDBAtlasVectorDB): The MongoDB vector database instance.
vector_search_engine (MongoDBAtlasVectorSearch): The vector search engine.
storage_context (StorageContext): The storage context for the vector store.
index (Optional[VectorStoreIndex]): The index built from the documents.
Initializes a MongoDBQueryEngine instance.
Parameters:
Instance Methods
add_docs
This method validates that the index exists, loads documents from the specified directory or file paths, and inserts them into the vector store index.
Parameters:
connect_db
This method verifies the existence of the collection, sets up the database connection, builds the vector store index, and pings the MongoDB server.
Returns:
bool: True if connection is successful; False otherwise. Parameters:
Returns:
get_collection_name
Returns:
str: The collection name.
Raises:
ValueError: If the collection name is not set. Returns:
init_db
This method loads documents from a directory or provided file paths, sets up the database (optionally overwriting any existing collection), builds the vector store index, and inserts the documents.
Parameters:
Returns:
query
This method validates that the query index is initialized, creates a query engine from the vector store index, and executes the query. If the response is empty, a default reply is returned.
Parameters:
Returns: