Matching Engine uses the wrong method "embed_documents" for embedding the query
Labels: name: area: embeddings, name: area: vector store, name: auto:bug, name: auto:improvement

### System Info

Matching Engine uses the wrong method "embed_documents" for embedding the query. Therefore when using things like HyDE, it just embeds the query verbatim without first running a chain to generate a hypothetical answer.

### Who can help?

@hwchase17 
@agola11 



### Information

- [X] The official example notebooks/scripts
- [ ] My own modified scripts

### Related Components

- [ ] LLMs/Chat Models
- [X] Embedding Models
- [ ] Prompts / Prompt Templates / Prompt Selectors
- [ ] Output Parsers
- [ ] Document Loaders
- [X] Vector Stores / Retrievers
- [ ] Memory
- [ ] Agents / Agent Executors
- [ ] Tools / Toolkits
- [ ] Chains
- [ ] Callbacks/Tracing
- [ ] Async

### Reproduction

Create an instance of an existing matching engine vector store. Supply a HyDE embedding as embedding model:
```
from langchain.llms import VertexAI
from langchain.embeddings import VertexAIEmbeddings
from langchain.vectorstores.matching_engine import MatchingEngine
from langchain.chains import HypotheticalDocumentEmbedder


langchain_PaLM_embeddings = VertexAIEmbeddings()
PaLM_llm = VertexAI()

HyDE = HypotheticalDocumentEmbedder.from_llm(PaLM_llm, langchain_PaLM_embeddings, "web_search")

vector_store = MatchingEngine.from_components(
    project_id = PROJECT_ID,
    region = "us-central1",
    index_id = INDEX_ID,
    endpoint_id = ENDPOINT_ID,
    gcs_bucket_name = BUCKET_NAME,
    embedding = HyDE
)
```

Then when asked a query, the matching engine code is written to call the `.embed_document()` method of the underlying embedding model on that query. However, it should call the `.embed_query()` method of that embedding model (see the line denoted with double stars):

```
def similarity_search(
        self, query: str, k: int = 4, **kwargs: Any
    ) -> List[Document]:
        """Return docs most similar to query.
        Args:
            query: The string that will be used to search for similar documents.
            k: The amount of neighbors that will be retrieved.

        Returns:
            A list of k matching documents.
        """

        logger.debug(f"Embedding query {query}.")
        **embedding_query = self.embedding.embed_documents([query])** # THIS IS THE PROBLEMATIC LINE

        response = self.endpoint.match(
            deployed_index_id=self._get_index_id(),
            queries=embedding_query,
            num_neighbors=k,
        )

        if len(response) == 0:
            return []

        logger.debug(f"Found {len(response)} matches for the query {query}.")

        results = []

        # I'm only getting the first one because queries receives an array
        # and the similarity_search method only receives one query. This
        # means that the match method will always return an array with only
        # one element.
        for doc in response[0]:
            page_content = self._download_from_gcs(f"documents/{doc.id}")
            results.append(Document(page_content=page_content))

        logger.debug("Downloaded documents for query.")

        return results
```


### Expected behavior

We can simply change that line to call the .embed_query method. This will result in calling the correct method for a hypothetical document embedding chain if it was used. If `embed_document` is used, it will not call the chain in HyDE to first generate a hypothetical answer. If `embed_query` is used, it will first call the chain to generate a hypothetical answer and then embed that answer.
I have done so and fixed it [in my PR](https://github.com/langchain-ai/langchain/pull/6094). The PR also provides support for Firestore along with matching engine as document storage:

```
def similarity_search(
        self, query: str, k: int = 4, **kwargs: Any
    ) -> List[Document]:
        """Return docs most similar to query.
        Args:
            query: The string that will be used to search for similar documents.
            k: The amount of neighbors that will be retrieved.

        Returns:
            A list of k matching documents.
        """

        logger.debug(f"Embedding query {query}.")
        **embedding_query = self.embedding.embed_query([query])** # Fixed by simply changing the method.

        response = self.endpoint.match(
            deployed_index_id=self._get_index_id(),
            queries=embedding_query,
            num_neighbors=k,
        )

        if len(response) == 0:
            return []

        logger.debug(f"Found {len(response)} matches for the query {query}.")

        results = []

        # I'm only getting the first one because queries receives an array
        # and the similarity_search method only receives one query. This
        # means that the match method will always return an array with only
        # one element.
        for doc in response[0]:
            page_content = self._download_from_gcs(f"documents/{doc.id}")
            results.append(Document(page_content=page_content))

        logger.debug("Downloaded documents for query.")

        return results
```