Repository: langchain
Issue: embedding_key param does not work in MongoDBAtlasVectorSearch
Labels: Ɑ: vector store

### Checked other resources

- [X] I added a very descriptive title to this issue.
- [X] I searched the LangChain documentation with the integrated search.
- [X] I used the GitHub search to find a similar question and didn't find it.
- [X] I am sure that this is a bug in LangChain rather than my code.
- [X] The bug is not resolved by updating to the latest stable version of LangChain (or the specific integration package).

### Description

This next code throws an error related to the embedding_key field :
`inference_api_key = os.getenv("OPENAI_API_KEY")
mongodb_cluster_uri = os.getenv("MONGODB_ATLAS_CLUSTER_URI")
db_name = os.getenv("DB_NAME")
collection_name = os.getenv("COLLECTION_NAME")
atlas_vector_search_index_name = os.getenv("ATLAS_VECTOR_SEARCH_INDEX_NAME")


embeddings = OpenAIEmbeddings(openai_api_key=inference_api_key,model="text-embedding-ada-002")
vector = embeddings.embed_query("hello")
print(vector[:3])

client = MongoClient(mongodb_cluster_uri)
collection = client[db_name][collection_name]

vector_store = MongoDBAtlasVectorSearch(
    collection=collection,
    embedding=embeddings,
    embedding_key="log_message_embedding",
    relevance_score_fn="cosine",
)

query = "Has any goal been aborted?"
results = vector_store.similarity_search(query)

pprint.pprint(results) `


It returns this error
`pymongo.errors.OperationFailure: PlanExecutor error during aggregation :: caused by :: embedding is not indexed as vector, full error: {'ok': 0.0, 'errmsg': 'PlanExecutor error during aggregation :: caused by :: embedding is not indexed as vector', 'code': 8, 'codeName': 'UnknownError', '$clusterTime': {'clusterTime': Timestamp(1728299912, 6), 'signature': {'hash': b"X\xe6!2\xb9\xc7P\xd66Q\x85g\x98'\x91\xe9\xfa\x0cH ", 'keyId': 7384849210639646731}}, 'operationTime': Timestamp(1728299912, 6)}`


The code is trying to use embedding instead of the embedding key value I indicated.
Thanks in advance

### Error Message and Stack Trace (if applicable)

`pymongo.errors.OperationFailure: PlanExecutor error during aggregation :: caused by :: embedding is not indexed as vector, full error: {'ok': 0.0, 'errmsg': 'PlanExecutor error during aggregation :: caused by :: embedding is not indexed as vector', 'code': 8, 'codeName': 'UnknownError', '$clusterTime': {'clusterTime': Timestamp(1728299912, 6), 'signature': {'hash': b"X\xe6!2\xb9\xc7P\xd66Q\x85g\x98'\x91\xe9\xfa\x0cH ", 'keyId': 7384849210639646731}}, 'operationTime': Timestamp(1728299912, 6)}`



### System Info

System Information

------------------

> OS:  Linux

> OS Version:  #45~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Wed Sep 11 15:25:05 UTC 2

> Python Version:  3.10.0 (default, Mar  3 2022, 09:58:08) [GCC 7.5.0]



Package Information

-------------------

 langchain_core: 0.3.9
 langchain: 0.3.1
 langchain_community: 0.3.1
 langsmith: 0.1.131
 langchain_mongodb: 0.2.0
 langchain_openai: 0.2.2
 langchain_text_splitters: 0.3.0


Optional packages not installed

-------------------------------

> langgraph

> langserve



Other Dependencies

------------------

> aiohttp: 3.10.9

> async-timeout: 4.0.3

> dataclasses-json: 0.6.7

> httpx: 0.27.2

> jsonpatch: 1.33

> numpy: 1.26.4

> openai: 1.51.0

> orjson: 3.10.7

> packaging: 24.1

> pydantic: 2.9.2

> pydantic-settings: 2.5.2

> pymongo: 4.9.1

> PyYAML: 6.0.2

> requests: 2.32.3

> requests-toolbelt: 1.0.0

> SQLAlchemy: 2.0.35

> tenacity: 8.5.0

> tiktoken: 0.8.0

> typing-extensions: 4.12.2