langchain/libs/partners/mongodb
Christophe Bornet 038c287b3a
all: Improve make lint command (#25344)
* Removed `ruff check --select I` as `I` is already selected and checked
in the main `ruff check` command
* Added checks for non-empty `PYTHON_FILES`
* Run `ruff check` only on `PYTHON_FILES`

Co-authored-by: Erick Friis <erick@langchain.dev>
2024-08-23 18:23:52 -07:00
..
langchain_mongodb partners: Use simsimd types (#25299) 2024-08-23 10:41:39 -04:00
scripts patch[Partners] Unified fix of incorrect variable declarations in all check_imports (#25014) 2024-08-03 13:49:41 -04:00
tests limit the most recent documents to fetch from MongoDB database. (#25435) 2024-08-22 10:33:45 -04:00
.gitignore
LICENSE
Makefile all: Improve make lint command (#25344) 2024-08-23 18:23:52 -07:00
poetry.lock partners: Use simsimd types (#25299) 2024-08-23 10:41:39 -04:00
pyproject.toml partners: Use simsimd types (#25299) 2024-08-23 10:41:39 -04:00
README.md mongodb: Add Hybrid and Full-Text Search Retrievers, release 0.2.0 (#25057) 2024-08-07 20:10:29 +00:00

langchain-mongodb

Installation

pip install -U langchain-mongodb

Usage

Using MongoDBAtlasVectorSearch

from langchain_mongodb import MongoDBAtlasVectorSearch

# Pull MongoDB Atlas URI from environment variables
MONGODB_ATLAS_CLUSTER_URI = os.environ.get("MONGODB_ATLAS_CLUSTER_URI")

DB_NAME = "langchain_db"
COLLECTION_NAME = "test"
ATLAS_VECTOR_SEARCH_INDEX_NAME = "index_name"
MONGODB_COLLECTION = client[DB_NAME][COLLECTION_NAME]

# Create the vector search via `from_connection_string`
vector_search = MongoDBAtlasVectorSearch.from_connection_string(
    MONGODB_ATLAS_CLUSTER_URI,
    DB_NAME + "." + COLLECTION_NAME,
    OpenAIEmbeddings(disallowed_special=()),
    index_name=ATLAS_VECTOR_SEARCH_INDEX_NAME,
)

# Initialize MongoDB python client
client = MongoClient(MONGODB_ATLAS_CLUSTER_URI)
# Create the vector search via instantiation
vector_search_2 = MongoDBAtlasVectorSearch(
    collection=MONGODB_COLLECTION,
    embeddings=OpenAIEmbeddings(disallowed_special=()),
    index_name=ATLAS_VECTOR_SEARCH_INDEX_NAME,
)