Repository: langchain
Issue: [Bug] Azure cosmos db no sql vector store similarity search method "mmr"
Labels: Ɑ: vector store,🤖:bug

### 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).

### Example Code

```python

from langchain_openai import AzureOpenAIEmbeddings
from langchain_community.vectorstores.azure_cosmos_db import AzureCosmosDBVectorSearch

azure_endpoint = "here_goes_azure_endpoint" 
openai_api_version = "2023-12-01-preview"
openai_api_key = "here_goes_api_key" 

embeddings = AzureOpenAIEmbeddings(
                    model="text-embedding-ada-002",
                    deployment="text-embedding-ada-002",
                    azure_endpoint=azure_endpoint,
                    openai_api_version=openai_api_version,
                    openai_api_key=openai_api_key
                )

azure_cosmos_db_connection_string = "here_goes_connection string" 
namespace = "here_goes_namespace" 
index_name = "here_goes_index_name" 

vs = AzureCosmosDBVectorSearch.from_connection_string(azure_cosmos_db_connection_string,
                                                                  namespace, embeddings,
                                                                  index_name=index_name)
docs_with_scores = vs.max_marginal_relevance_search(query, k=8)
```

### Error Message and Stack Trace (if applicable)

```txt 

File \site-packages\langchain_community\vectorstores\azure_cosmos_db_no_sql.py:363, in AzureCosmosDBNoSqlVectorSearch.max_marginal_relevance_search_by_vector(self, embedding, k, fetch_k, lambda_mult, **kwargs)
    [361](/langchain_community/vectorstores/azure_cosmos_db_no_sql.py:361) if kwargs["with_embedding"]:
    [362](/langchain_community/vectorstores/azure_cosmos_db_no_sql.py:362)     with_embedding = kwargs["with_embedding"]
--> [363](/langchain_community/vectorstores/azure_cosmos_db_no_sql.py:363) docs = self._similarity_search_with_score(
    [364](/langchain_community/vectorstores/azure_cosmos_db_no_sql.py:364)     embeddings=embedding,
    [365](/langchain_community/vectorstores/azure_cosmos_db_no_sql.py:365)     k=fetch_k,
    [366](/langchain_community/vectorstores/azure_cosmos_db_no_sql.py:366)     pre_filter=pre_filter,
    [367](/langchain_community/vectorstores/azure_cosmos_db_no_sql.py:367)     with_embedding=with_embedding,
    [368](/langchain_community/vectorstores/azure_cosmos_db_no_sql.py:368) )
    [370](/langchain_community/vectorstores/azure_cosmos_db_no_sql.py:370) # Re-ranks the docs using MMR
    [371](/langchain_community/vectorstores/azure_cosmos_db_no_sql.py:371) mmr_doc_indexes = maximal_marginal_relevance(
    [372](/langchain_community/vectorstores/azure_cosmos_db_no_sql.py:372)     np.array(embedding),
    [373](/langchain_community/vectorstores/azure_cosmos_db_no_sql.py:373)     [doc.metadata[self._embedding_key] for doc, _ in docs],
    [374](/langchain_community/vectorstores/azure_cosmos_db_no_sql.py:374)     k=k,
    [375](/langchain_community/vectorstores/azure_cosmos_db_no_sql.py:375)     lambda_mult=lambda_mult,
    [376](/langchain_community/vectorstores/azure_cosmos_db_no_sql.py:376) )

File \site-packages\langchain_community\vectorstores\azure_cosmos_db_no_sql.py:308, in AzureCosmosDBNoSqlVectorSearch._similarity_search_with_score(self, embeddings, k, pre_filter, with_embedding)
    [306](/langchain_community/vectorstores/azure_cosmos_db_no_sql.py:306) score = item["SimilarityScore"]
    [307](/langchain_community/vectorstores/azure_cosmos_db_no_sql.py:307) if with_embedding:
--> [308](/langchain_community/vectorstores/azure_cosmos_db_no_sql.py:308)     metadata[self._embedding_key] = item[self._embedding_key]
    [309](/langchain_community/vectorstores/azure_cosmos_db_no_sql.py:309) metadata['SimilarityScore'] = score
    [310](/langchain_community/vectorstores/azure_cosmos_db_no_sql.py:310) docs_and_scores.append(
    [311](/langchain_community/vectorstores/azure_cosmos_db_no_sql.py:311)     (Document(page_content=text, metadata=metadata), score)
    [312](/langchain_community/vectorstores/azure_cosmos_db_no_sql.py:312) )

KeyError: 'embedding'
```

### Description

The problem here is two fold : 
* with_embedding kwargs argument is not working ([issues/26097](https://github.com/langchain-ai/langchain/issues/26097))
* in turn causes the "mmr" search type method to fails because it requires embedding in the metadata of the resulting documents

note: "with_embedding" needs to be true for mmr search to work properly

Why did this issue happen ? --> an update to the query made to cosmos db resulted in items that don't have embedding as key. [pull/27377](https://github.com/langchain-ai/langchain/pull/27377)
 

### System Info

```

System Information
------------------
> OS:  Windows
> OS Version:  10.0.22631
> Python Version:  3.12.0 (tags/v3.12.0:0fb18b0, Oct  2 2023, 13:03:39) [MSC v.1935 64 bit (AMD64)]

Package Information
-------------------
> langchain_core: 0.3.21
> langchain: 0.3.9
> langchain_community: 0.3.9
> langsmith: 0.1.147
> langchain_cohere: 0.3.3
> langchain_experimental: 0.3.3
> langchain_openai: 0.2.10
> langchain_text_splitters: 0.3.2
> langgraph_sdk: 0.1.40

Optional packages not installed
-------------------------------
> langserve

Other Dependencies
------------------
> aiohttp: 3.11.9
> async-timeout: Installed. No version info available.
> cohere: 5.13.0
> dataclasses-json: 0.6.7
> httpx: 0.28.0
> httpx-sse: 0.4.0
> jsonpatch: 1.33
> langsmith-pyo3: Installed. No version info available.
> numpy: 1.26.4
> openai: 1.56.0
> orjson: 3.10.12
> packaging: 24.2
> pandas: 2.2.3
> pydantic: 2.10.2
> pydantic-settings: 2.6.1
> PyYAML: 6.0.2
> requests: 2.32.3
> requests-toolbelt: 1.0.0
> SQLAlchemy: 2.0.36
> tabulate: 0.9.0
> tenacity: 9.0.0
> tiktoken: 0.7.0
> typing-extensions: 4.12.2
```