Skill

Load MongoDB Data for LlamaIndex

Load data from MongoDB into LlamaIndex with this SimpleMongoReader. Concatenate specified fields from MongoDB documents.

Works with mongodbllamaindexlangchain

77
Spark score
out of 100
Updated 5 months ago
Version 1.0.0
Models

Add to Favorites

Why it matters

Effortlessly ingest and prepare your MongoDB data for use with LlamaIndex. This integration allows you to easily load documents, specifying fields and filters, to power your AI applications.

Outcomes

What it gets done

01

Connect to MongoDB databases and collections.

02

Select and concatenate specific fields from documents.

03

Filter documents using custom query dictionaries.

04

Prepare data for LlamaIndex or LangChain agents.

Install

Add it to your toolbox

Run in your project directory:

curl -fsSL https://spark.entire.vc/get/li-reader-readers-mongodb | bash

Overview

LlamaIndex Readers Integration: Mongo

A Python package that loads data from MongoDB databases into LlamaIndex Use when you need to load MongoDB documents into LlamaIndex for indexing and retrieval

What it does

This integration provides a SimpleMongoReader for LlamaIndex, enabling the loading of data directly from a MongoDB database. It concatenates specified fields from each MongoDB document into a single document, making the data usable by LlamaIndex.

When to use - and when NOT to

Use this reader when you need to ingest data stored in MongoDB into your LlamaIndex pipelines. Do not use this reader if your data is not stored in MongoDB or if you do not intend to use it with the LlamaIndex framework.

Inputs and outputs

The reader takes connection details for your MongoDB instance (host, port, or URI), database name, collection name, and optionally, field names to concatenate, a separator, a query dictionary for filtering, a maximum number of documents to load, and metadata field names. The output is a list of documents, where each document contains the concatenated content from the specified fields of a MongoDB record.

Integrations

This loader is designed to be used as a way to load data into LlamaIndex and/or subsequently used as a Tool in a LangChain Agent.

Who it's for

This integration is for developers working with LlamaIndex and MongoDB.

pip install llama-index-readers-mongodb
from llama_index.readers.mongodb import SimpleMongoReader

### Initialize SimpleMongoReader
reader = SimpleMongoReader(
    host="<Mongo Host>",  # Mongo host address
    port=27017,  # Mongo port (default: 27017)
    uri="<Mongo Connection String>",  # Provide the URI if not using host and port
)

### Lazy load data from MongoDB
documents = reader.lazy_load_data(
    db_name="<Database Name>",  # Name of the database
    collection_name="<Collection Name>",  # Name of the collection
    field_names=[
        "text"
    ],  # Names of the fields to concatenate (default: ["text"])
    separator="",  # Separator between fields (default: "")
    query_dict=None,  # Query to filter documents (default: None)
    max_docs=0,  # Maximum number of documents to load (default: 0)
    metadata_names=None,  # Names of the fields to add to metadata attribute (default: None)
)
Source README

LlamaIndex Readers Integration: Mongo

Overview

Simple Mongo Reader allows loading data from a MongoDB database. It concatenates specified fields from each document into a single document used by LlamaIndex.

Installation

You can install MongoDB Reader via pip:

pip install llama-index-readers-mongodb

Usage

from llama_index.readers.mongodb import SimpleMongoReader

### Initialize SimpleMongoReader
reader = SimpleMongoReader(
    host="<Mongo Host>",  # Mongo host address
    port=27017,  # Mongo port (default: 27017)
    uri="<Mongo Connection String>",  # Provide the URI if not using host and port
)

### Lazy load data from MongoDB
documents = reader.lazy_load_data(
    db_name="<Database Name>",  # Name of the database
    collection_name="<Collection Name>",  # Name of the collection
    field_names=[
        "text"
    ],  # Names of the fields to concatenate (default: ["text"])
    separator="",  # Separator between fields (default: "")
    query_dict=None,  # Query to filter documents (default: None)
    max_docs=0,  # Maximum number of documents to load (default: 0)
    metadata_names=None,  # Names of the fields to add to metadata attribute (default: None)
)

Implementation for MongoDB reader can be found here

This loader is designed to be used as a way to load data into
LlamaIndex and/or subsequently
used as a Tool in a LangChain Agent.

FAQ

Common questions

Discussion

Questions & comments · 0

Sign In Sign in to leave a comment.