-
Notifications
You must be signed in to change notification settings - Fork 14k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
partners: MongoDB Partner Package -- Porting MongoDBAtlasVectorSearch #17652
Merged
efriis
merged 27 commits into
langchain-ai:master
from
Jibola:partner-package-mongodbatlas
Feb 29, 2024
Merged
Changes from 12 commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
321ca5b
MongoDB Partner Package -- first pass
Jibola 34ddb1d
Merge branch 'master' into partner-package-mongodbatlas
Jibola edeb555
kept the vectorsearch names and kept the mongodbatlasvectorsearch nam…
Jibola 0052663
remove docs section
Jibola 05d46e7
make format
Jibola 4e751d9
make format && make lint
Jibola 82e7eb4
Merge branch 'master' into partner-package-mongodbatlas
Jibola ba82b0f
added some more unit tests; removed duplicate import test statement
Jibola 0921e47
deprecate langchain_community implementation
Jibola 40ee1ac
updated the README.md to include usage instructions; 'beefed up' unit…
Jibola e0c81e1
set batch sizing back to 100
Jibola bde5a3c
Update libs/partners/mongodb-atlas/README.md
Jibola b156250
rename mongodb-atlas -> mongodb; update dependencies
Jibola fc36819
updaetd poetry.lock
Jibola c7f58de
Merge branch 'master' into partner-package-mongodbatlas
Jibola e3f9b3c
Merge branch 'master' into partner-package-mongodbatlas
efriis dbdc50f
format
efriis fcb04e1
deprecation version
efriis 027bcb8
x
efriis 68c9d56
fix typing in vectorstores tests and return test_compile placeholder
Jibola 837eec1
rename documentation to import langchain_mongodb rather than langchai…
Jibola 5fb1c14
fix integration_test validity checks & consolidate embedder
Jibola 542bbc8
Merge branch 'master' into partner-package-mongodbatlas
efriis a869240
test
efriis a74c952
doc nit
efriis 0f2ea82
x
efriis cf5b5d4
x
efriis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
__pycache__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2023 LangChain, Inc. | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
.PHONY: all format lint test tests integration_tests docker_tests help extended_tests | ||
|
||
# Default target executed when no arguments are given to make. | ||
all: help | ||
|
||
# Define a variable for the test file path. | ||
TEST_FILE ?= tests/unit_tests/ | ||
|
||
test: | ||
poetry run pytest $(TEST_FILE) | ||
|
||
tests: | ||
poetry run pytest $(TEST_FILE) | ||
|
||
|
||
###################### | ||
# LINTING AND FORMATTING | ||
###################### | ||
|
||
# Define a variable for Python and notebook files. | ||
PYTHON_FILES=. | ||
MYPY_CACHE=.mypy_cache | ||
lint format: PYTHON_FILES=. | ||
lint_diff format_diff: PYTHON_FILES=$(shell git diff --relative=libs/partners/mongodb-atlas --name-only --diff-filter=d master | grep -E '\.py$$|\.ipynb$$') | ||
lint_package: PYTHON_FILES=langchain_mongodb_atlas | ||
lint_tests: PYTHON_FILES=tests | ||
lint_tests: MYPY_CACHE=.mypy_cache_test | ||
|
||
lint lint_diff lint_package lint_tests: | ||
poetry run ruff . | ||
poetry run ruff format $(PYTHON_FILES) --diff | ||
poetry run ruff --select I $(PYTHON_FILES) | ||
mkdir $(MYPY_CACHE); poetry run mypy $(PYTHON_FILES) --cache-dir $(MYPY_CACHE) | ||
|
||
format format_diff: | ||
poetry run ruff format $(PYTHON_FILES) | ||
poetry run ruff --select I --fix $(PYTHON_FILES) | ||
|
||
spell_check: | ||
poetry run codespell --toml pyproject.toml | ||
|
||
spell_fix: | ||
poetry run codespell --toml pyproject.toml -w | ||
|
||
check_imports: $(shell find langchain_mongodb_atlas -name '*.py') | ||
poetry run python ./scripts/check_imports.py $^ | ||
|
||
###################### | ||
# HELP | ||
###################### | ||
|
||
help: | ||
@echo '----' | ||
@echo 'check_imports - check imports' | ||
@echo 'format - run code formatters' | ||
@echo 'lint - run linters' | ||
@echo 'test - run unit tests' | ||
@echo 'tests - run unit tests' | ||
@echo 'test TEST_FILE=<test_file> - run all tests in file' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# langchain-mongodb-atlas | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should at least have Installation and Usage sections here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. supplied! |
||
|
||
# Installation | ||
``` | ||
pip install -U langchain-mongodb-atlas | ||
``` | ||
|
||
# Usage | ||
- See [integrations doc](../../../docs/docs/integrations/vectorstores/mongodb_atlas.ipynb) for more in-depth usage instructions. | ||
- See [Getting Started with the LangChain Integration](https://www.mongodb.com/docs/atlas/atlas-vector-search/ai-integrations/langchain/#get-started-with-the-langchain-integration) for a walkthrough on using your first LangChain implementation with MongoDB Atlas. | ||
|
||
## Using MongoDBAtlasVectorSearch | ||
```python | ||
from langchain_community.vectorstores 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][COLLECITON_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, | ||
) | ||
``` |
7 changes: 7 additions & 0 deletions
7
libs/partners/mongodb-atlas/langchain_mongodb_atlas/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from langchain_mongodb_atlas.vectorstores import ( | ||
MongoDBAtlasVectorSearch, | ||
) | ||
|
||
__all__ = [ | ||
"MongoDBAtlasVectorSearch", | ||
] |
Empty file.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not ideal to duplicate this whole class implementation. Instead can we make this a thin wrapper around langchain_mongodb_atlas.MongoDBAtlasVectorSearch?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we'll be able to do that because the partner-package ends up needing a completely separate pip installation to use. I imagine having to import
langchain_mongodb_atlas
introduces a breaking change for folks using this class.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah I see, so the duplication is unavoidable in this case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, unless @efriis has any suggestions?