Skip to content
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

community: [MongoDBAtlasVectorSearch] Fix KeyError 'embedding' when using MMR #17963

Closed
4 tasks done
certified-dodo opened this issue Feb 22, 2024 · 1 comment
Closed
4 tasks done
Labels
🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature 🔌: openai Primarily related to OpenAI integrations Ɑ: vector store Related to vector store module

Comments

@certified-dodo
Copy link
Contributor

certified-dodo commented Feb 22, 2024

Checked other resources

  • I added a very descriptive title to this issue.
  • I searched the LangChain documentation with the integrated search.
  • I used the GitHub search to find a similar question and didn't find it.
  • I am sure that this is a bug in LangChain rather than my code.

Example Code

# test.py
from langchain_openai import OpenAIEmbeddings
from langchain_community.vectorstores.mongodb_atlas import MongoDBAtlasVectorSearch

embeddings = OpenAIEmbeddings()

MONGO_CONNECTION_URI = "mongo uri"
VECTORS_DB_NAME = "db name"
VECTOR_SEARCH_INDEX_NAME = "index name"

db = MongoDBAtlasVectorSearch.from_connection_string(
    MONGO_CONNECTION_URI,
    VECTORS_DB_NAME,
    embeddings,
    index_name=VECTOR_SEARCH_INDEX_NAME,
)

db_query = "Find info related to ..."
num_of_db_results = 10

raw_contexts = db.max_marginal_relevance_search(query=db_query, k=num_of_db_results, lambda_mult=0)

Error Message and Stack Trace (if applicable)

Traceback (most recent call last):
  File ".../test.py", line 39, in <module>
    raw_contexts = db.max_marginal_relevance_search(query=db_query, k=num_of_db_results, lambda_mult=0)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../lib/python3.12/site-packages/langchain_community/vectorstores/mongodb_atlas.py", line 325, in max_marginal_relevance_search
    [doc.metadata[self._embedding_key] for doc, _ in docs],
     ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^
KeyError: 'embedding'

Description

Expectation

  • MMR option working with no error

System Info

Python
v3.12.0

requirements.txt

langchain==0.1.8
langchain-community==0.0.21
langchain-core==0.1.25
langchain-openai==0.0.5
langsmith==0.1.5
openai==1.11.1
@dosubot dosubot bot added Ɑ: vector store Related to vector store module 🔌: openai Primarily related to OpenAI integrations 🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature labels Feb 22, 2024
certified-dodo added a commit to certified-dodo/langchain that referenced this issue Feb 22, 2024
@certified-dodo
Copy link
Contributor Author

#17971

baskaryan added a commit that referenced this issue Mar 1, 2024
…_search (#17971)

Description:
* `self._embedding_key` is accessed after deletion, breaking
`max_marginal_relevance_search` search
* Introduced in:
e135e52
* Updated but still persists in:
ce22e10

Issue: #17963

Co-authored-by: Bagatur <baskaryan@gmail.com>
gkorland pushed a commit to FalkorDB/langchain that referenced this issue Mar 30, 2024
…_search (langchain-ai#17971)

Description:
* `self._embedding_key` is accessed after deletion, breaking
`max_marginal_relevance_search` search
* Introduced in:
langchain-ai@e135e52
* Updated but still persists in:
langchain-ai@ce22e10

Issue: langchain-ai#17963

Co-authored-by: Bagatur <baskaryan@gmail.com>
@dosubot dosubot bot added the stale Issue has not had recent activity or appears to be solved. Stale issues will be automatically closed label Jun 1, 2024
@dosubot dosubot bot closed this as not planned Won't fix, can't repro, duplicate, stale Jun 8, 2024
@dosubot dosubot bot removed the stale Issue has not had recent activity or appears to be solved. Stale issues will be automatically closed label Jun 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature 🔌: openai Primarily related to OpenAI integrations Ɑ: vector store Related to vector store module
Projects
None yet
Development

No branches or pull requests

1 participant