delayedkarma/langchain-issues huggingface dataset:
vector_db.similarity_search(request.query,k=2) Not working with the opensearch index
Labels: name: area: embeddings, name: area: doc loader, name: area: vector store, name: auto:bug

### System Info

I have 2000 document present at my opensearch index, i have filter out the 2 documents present from this opensearch index and added to newly created index. After that i am trying to use vector_db.similarity_search(request.query,k=2) on the newly created index, its returning me empty list. 
below are the code

Code for index creation:
updated_mapping = {"mappings":{"properties": {"vector_field": {"type": "knn_vector","dimension": 1536,"method": {"engine": "nmslib","space_type": "l2","name": "hnsw","parameters": {"ef_construction": 512,"m": 16}}}}}}
opensearch_client.indices.create(index="temp_check878999", body=updated_mapping)


Code to update the index with filtered document:
sea=["1460210.pdf",'P-Reality-X Manuscript_Draft 1_17Feb22 (PAL1144).pdf']
for i in sea:
    query={"query":{
          "match":{
              "metadata.filename":f"*{i}"
          }
      }}
    print(query)
    rest=opensearch_client.search(index="lang_demo",body=query)
    create=rest['hits']['hits']
    for hit in create:
        sr=hit['_source']
        doc_id=hit['_id']

        opensearch_client.index(index="temp_check878999",id=doc_id,body=sr)

Langchain simillarity search code i am using on newly created index
from langchain.vectorstores import OpenSearchVectorSearch
vector_db = OpenSearchVectorSearch(
            index_name="temp_check878999",
            embedding_function=embed_wrapper(engine="text-embedding-ada-002"),
            opensearch_url=*****,
            http_auth=(******, *****),
            is_aoss=False,
        )
vector_db.similarity_search("star",k=2)

Quick reply will be very much helpful

### Who can help?

_No response_

### Information

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

### Related Components

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

### Reproduction

No idea

### Expected behavior

It should return me the simmilarity search text with newly created index. Please note its working fine on the index where i had used vector_db.addtext(text). This issue is if i create the new open search index with opensearch client then on that index the simmilarity search one is not working.
autonomous_agents : poetry run mypy . with experimental fails with langchain version 0.0.278
Labels: name: auto:bug, name: area: models

### System Info

langchain 0.0.278.

I try to publish a pull request in the project experimental. I must update the dependencies of langchain, but I receive a lot of errors.
See [here](https://github.com/langchain-ai/langchain/actions/runs/6047844508/job/16412056269?pr=7278), outside of my code.

### Who can help?

@hwchase17

### Information

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

### Related Components

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

### Reproduction

In the libs/experimental/pyproject.toml, change:
langchain = ">=0.0.278"

then

     poetry run mypy .

### Expected behavior

No error
When I call the 'loader()' function of AsyncHtmlLoader, I receive an 'Event loop is closed' error after it completes execution.
Labels: name: area: doc loader, name: auto:bug

### System Info

LangChain: 0.0.278
python: 3.10
windows10

### Who can help?

_No response_

### Information

- [X] The official example notebooks/scripts
- [ ] My own modified scripts

### Related Components

- [ ] LLMs/Chat Models
- [ ] Embedding Models
- [ ] Prompts / Prompt Templates / Prompt Selectors
- [ ] Output Parsers
- [X] Document Loaders
- [ ] Vector Stores / Retrievers
- [ ] Memory
- [ ] Agents / Agent Executors
- [ ] Tools / Toolkits
- [ ] Chains
- [ ] Callbacks/Tracing
- [ ] Async

### Reproduction

I wrote with reference to[ this link](https://python.langchain.com/docs/use_cases/web_scraping#asynchtmlloader), and the code is as follows: 
```python
from langchain.document_loaders import `AsyncHtmlLoader`

urls = ['https://python.langchain.com/docs/use_cases/web_scraping#asynchtmlloader']
loader = AsyncHtmlLoader(urls)
doc = loader.load()
print(doc)
```
Return the following error after running:
```
Exception ignored in: <function _ProactorBasePipeTransport.__del__ at 0x0000023EFFD45900>
Traceback (most recent call last):
  File "C:\Users\97994\AppData\Local\Programs\Python\Python310\lib\asyncio\proactor_events.py", line 116, in __del__
    self.close()
  File "C:\Users\97994\AppData\Local\Programs\Python\Python310\lib\asyncio\proactor_events.py", line 108, in close
    self._loop.call_soon(self._call_connection_lost, None)
  File "C:\Users\97994\AppData\Local\Programs\Python\Python310\lib\asyncio\base_events.py", line 750, in call_soon
    self._check_closed()
  File "C:\Users\97994\AppData\Local\Programs\Python\Python310\lib\asyncio\base_events.py", line 515, in _check_closed
    raise RuntimeError('Event loop is closed')
RuntimeError: Event loop is closed
```

### Expected behavior

None
Text splitting with keep_separator is True still removes any whitespace, even if separator is whitespace
Labels: name: auto:bug

```
text = "foo _bar_ baz_ 123"
separator = "_"

text_splitter = CharacterTextSplitter(
    chunk_size=4,
    chunk_overlap=0,
    separator="_",
    keep_separator=True,
)

print(text_splitter.split_text(text))
```
RETURNS:
`['foo', '_bar', '_ baz', '_ 123']`
EXPECTED:
`['foo ', '_bar', '_ baz', '_ 123']`

^see whitespace next to `foo`

https://github.com/langchain-ai/langchain/blame/324c86acd5be9bc9d5b6dd248d686bdbb2c11cdc/libs/langchain/langchain/text_splitter.py#L155 removes all whitespace from the text. I can't figure out the purpose of this line.
Added code to allow handle_parsing_error to pass into the AgentExecutor
Labels: name: area: agent, name: auto:improvement

  - Description: Fixed an issue with `create_pandas_dataframe_agent` where the `handle_parsing_variable` passed in does not get passed to the AgentExecutor, resulting in no difference in parsing error handling regardless of what value the variable had.
  - Issue: the issue #10045
  - Dependencies: No new dependencies
  - Tag maintainer: @baskaryan
Issue: chroma retriever where_document parameter passed in search_kwargs is invalid
Labels: name: area: vector store, name: auto:improvement

### Issue you'd like to raise.

I am using chroma db as retriever in ConversationalRetrievalChain, but the parameter "where_document" does not work.
```python
search_kwargs = {
    "k": k,
    "filter": filter,
    "where_document": {"$contains": "1000001"}
}
retriever = vectordb.as_retriever(
    search_kwargs=search_kwargs
)
```
In chroma official site [chroma](https://docs.trychroma.com/usage-guide), it says: 
Chroma supports filtering queries by metadata and document contents. The where filter is used to filter by metadata, and the where_document filter is used to filter by document contents.

### Suggestion:

can ConversationalRetrievalChain support where_document filter for chroma db?
Vectara query a already uploaded Corpus 
Labels: name: area: vector store, name: auto:question

### Issue you'd like to raise.

I have uploaded my files to Vectara and would love to query the corpus now with langchain. However I can only find examples of how to upload documents and then directly query them. I would like to avoid uploading the documents all the time and just straight query the existing corpus . Is this possible ?

Thank you so much! 

Regards 

### Suggestion:

_No response_
StructuredTool ainvoke isn't await parent class ainvoke
Labels: name: auto:bug

[code pointer](https://github.com/langchain-ai/langchain/blob/74fcfed4e2bdd186c2869a07008175a9b66b1ed4/libs/langchain/langchain/tools/base.py#L588C16-L588C16)

In `langchain.tools.base`, change 
```python
Class StructuredTool(BaseTool):
    """Tool that can operate on any number of inputs."""

    description: str = ""
    args_schema: Type[BaseModel] = Field(..., description="The tool schema.")
    """The input arguments' schema."""
    func: Optional[Callable[..., Any]]
    """The function to run when the tool is called."""
    coroutine: Optional[Callable[..., Awaitable[Any]]] = None
    """The asynchronous version of the function."""

    # --- Runnable ---

    async def ainvoke(
        self,
        input: Union[str, Dict],
        config: Optional[RunnableConfig] = None,
        **kwargs: Any,
    ) -> Any:
        if not self.coroutine:
            # If the tool does not implement async, fall back to default implementation
            return await asyncio.get_running_loop().run_in_executor(
                None, partial(self.invoke, input, config, **kwargs)
            )

        return super().ainvoke(input, config, **kwargs)
```

to 

```python
Class StructuredTool(BaseTool):
    """Tool that can operate on any number of inputs."""

    description: str = ""
    args_schema: Type[BaseModel] = Field(..., description="The tool schema.")
    """The input arguments' schema."""
    func: Optional[Callable[..., Any]]
    """The function to run when the tool is called."""
    coroutine: Optional[Callable[..., Awaitable[Any]]] = None
    """The asynchronous version of the function."""

    # --- Runnable ---

    async def ainvoke(
        self,
        input: Union[str, Dict],
        config: Optional[RunnableConfig] = None,
        **kwargs: Any,
    ) -> Any:
        if not self.coroutine:
            # If the tool does not implement async, fall back to default implementation
            return await asyncio.get_running_loop().run_in_executor(
                None, partial(self.invoke, input, config, **kwargs)
            )

        return await super().ainvoke(input, config, **kwargs)
```
ConversationTokenBufferMemory and ConversationSummaryBufferMemory does not work with db-backed histories
Labels: name: area: memory, name: auto:bug

### System Info

the memories are pruned after saving using .pop(0). However, db-backed histories read messages and copies into list each turn. This makes it so that the actual db does not change at every turn, and so max_token_limit parameter gets ignored and the memory prints out the entire conversation for history.

### Who can help?

_No response_

### Information

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

### Related Components

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

### Reproduction

Initialize redis chat history
use redis chat history as chat_history for ConversationSummaryBufferMemory
set max_token_limit to 1.
Print history at every turn.
Still prints the entire history

### Expected behavior

Initialize redis chat history
use redis chat history as chat_history for ConversationSummaryBufferMemory
set max_token_limit to 1.
Print history at every turn.
Print nothing since max_token_limit = 0
ElasticSearch authentication
Labels: name: area: vector store, name: auto:bug

### System Info

On the elasticsearch authentication, you have implemented it this way on the elasticsearch.py file found in the vectorstores folder

```py
if api_key:
            connection_params["api_key"] = api_key
        elif username and password:
            connection_params["basic_auth"] = (username, password)
```

but i think it should be this way 
```py
if api_key:
            connection_params["api_key"] = api_key
        elif username and password:
            connection_params["http_auth"] = (username, password)
```

with that change the authentication succeeeds. What i have just changed is this connection_params["basic_auth"] = (username, password) to this connection_params["http_auth"] = (username, password)

### Who can help?

_No response_

### Information

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

### Related Components

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

### Reproduction

Create an elasticsearch instance on an EC2 instance using docker that has SSL and also uses username and password and then try to authenticate to that elasticsearch instance using langchain you will see the error

### Expected behavior

The expected behavior is successfull authentication
use case docs reorder
Labels: name: auto:documentation

<!-- Thank you for contributing to LangChain!

Replace this entire comment with:
  - Description: a description of the change, 
  - Issue: the issue # it fixes (if applicable),
  - Dependencies: any dependencies required for this change,
  - Tag maintainer: for a quicker response, tag the relevant maintainer (see below),
  - Twitter handle: we announce bigger features on Twitter. If your PR gets announced and you'd like a mention, we'll gladly shout you out!

Please make sure your PR is passing linting and testing before submitting. Run `make format`, `make lint` and `make test` to check this locally.

See contribution guidelines for more information on how to write/run tests, lint, etc: 
https://github.com/hwchase17/langchain/blob/master/.github/CONTRIBUTING.md

If you're adding a new integration, please include:
  1. a test for the integration, preferably unit tests that do not rely on network access,
  2. an example notebook showing its use. These live is docs/extras directory.

If no one reviews your PR within a few days, please @-mention one of @baskaryan, @eyurtsev, @hwchase17, @rlancemartin.
 -->
Comprehend Moderation 0.1
Labels: name: auto:enhancement, name: area: models

This PR streamlines the #9665 configuration object and logic to enable chain moderation via the Amazon Comprehend service, allowing you to detect and redact PII, Toxic, and Intent information in the LLM prompt or answer. 
This implementation simplifies the configuration and types it to specific class/model.


### Usage sample

```python
from langchain_experimental.comprehend_moderation import (BaseModerationConfig, 
                                 ModerationIntentConfig, 
                                 ModerationPiiConfig, 
                                 ModerationToxicityConfig
)

pii_config = ModerationPiiConfig(
    labels=["SSN"],
    redact=True,
    mask_character="X"
)

toxicity_config = ModerationToxicityConfig(
    threshold=0.5
)

intent_config = ModerationIntentConfig(
    threshold=0.5
)

moderation_config = BaseModerationConfig(
    filters=[pii_config, toxicity_config, intent_config]
)

comp_moderation_with_config = AmazonComprehendModerationChain(
    moderation_config=moderation_config, #specify the configuration
    client=comprehend_client,            #optionally pass the Boto3 Client
    verbose=True
)

template = """Question: {question}

Answer:"""

prompt = PromptTemplate(template=template, input_variables=["question"])

responses = [
    "Final Answer: A credit card number looks like 1289-2321-1123-2387. A fake SSN number looks like 323-22-9980. John Doe's phone number is (999)253-9876.", 
    "Final Answer: This is a really shitty way of constructing a birdhouse. This is fucking insane to think that any birds would actually create their motherfucking nests here."
]
llm = FakeListLLM(responses=responses)

llm_chain = LLMChain(prompt=prompt, llm=llm)

chain = ( 
    prompt 
    | comp_moderation_with_config 
    | {llm_chain.input_keys[0]: lambda x: x['output'] }  
    | llm_chain 
    | { "input": lambda x: x['text'] } 
    | comp_moderation_with_config 
)

try:
    response = chain.invoke({"question": "A sample SSN number looks like this 123-456-7890. Can you give me some more samples?"})
except Exception as e:
    print(str(e))
else:
    print(response['output'])

```

### Output

```python
> Entering new AmazonComprehendModerationChain chain...
Running AmazonComprehendModerationChain...
Running pii Validation...
Running toxicity Validation...
Running intent Validation...

> Finished chain.


> Entering new AmazonComprehendModerationChain chain...
Running AmazonComprehendModerationChain...
Running pii Validation...
Running toxicity Validation...
Running intent Validation...

> Finished chain.
Final Answer: A credit card number looks like 1289-2321-1123-2387. A fake SSN number looks like XXXXXXXXXXXX John Doe's phone number is (999)253-9876.
```
Add example of running Q&A over structured data using the `Airbyte` loaders and `pandas`
Labels: name: area: doc loader, name: auto:documentation

  - Description: Added example of running Q&A over structured data using the `Airbyte` loaders and `pandas`
  - Dependencies: any dependencies required for this change,
  - Tag maintainer: @hwchase17 
  - Twitter handle: @pelaseyed
feat: Add `ApifyWrapper` class
Labels: name: auto:enhancement

If you look at documentation https://python.langchain.com/docs/integrations/tools/apify (or the actual file https://github.com/langchain-ai/langchain/blob/master/docs/extras/integrations/tools/apify.ipynb ), there's a class `ApifyWrapper` mentioned. It seems it got lost in some refactoring, i.e. it does not exist in the codebase ATM.

I just propose to add it back.
It would fix issues e.g. https://github.com/langchain-ai/langchain/issues/8307 or https://github.com/langchain-ai/langchain/issues/8201

To add, Apify is a wanted integration, e.g. see https://twitter.com/hwchase17/status/1695490295914545626 or https://twitter.com/hwchase17/status/1695470765343461756

Lastly, I offer taking ownership of the Apify-related parts of the codebase, so you can tag me if anything is needed.
Add SelfQueryRetriever support for Redis Vector Stores
Labels: name: area: vector store, name: auto:enhancement, name: integration: redis

### Feature request

Implement Self Query retriever to Redis vector stores.

### Motivation

I was trying the different retrievers for my project (AI chatbot that answers various human resources and labor law questions based on a dataset built from complete local labor legislation, company handbooks, job descriptions and SOPs).

I plan to deploy this chatbot in a production environment, therefore I chose Redis (for its robustness and speed) as a vector store.

### Your contribution

I am not a pro developer; so, unfortunately, the only contributions I can make is limited to "real-world" testing.
CustomLLM when called inside agent does not return custom behaviour
Labels: name: area: agent, name: auto:bug, name: area: models

### System Info

Langchain  0.0.276
Windows
Python 3.11.4

I create a custom llm just like in the tutorial but when i use it on a mkrl agent it does not return to the agent the custom response.
I printed insided my agent and it is called and returns the correct answer, but the agent in the end of line does not get this answer.




### Who can help?

@hwchase17 
@agola11

### Information

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

### Related Components

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

### Reproduction

https://colab.research.google.com/drive/1cHVx3GlzmF4ECV_63ZjlrMPt8P840GSw?usp=sharing

### Expected behavior

The expected behaviour is the agent to receive the response of the CustomLLM.
max_marginal_relevance_search not implemented in Redis
Labels: name: area: vector store, name: auto:enhancement

### System Info

LangChain version: 0.0.276
Python version: 3.11.2
Platform: x86_64 Debian 12.2.0-14

### Who can help?

_No response_

### Information

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

### Related Components

- [ ] LLMs/Chat Models
- [ ] 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

```python
import os, openai
from langchain.embeddings.openai import OpenAIEmbeddings
from langchain.vectorstores import Redis

embeddings = OpenAIEmbeddings()

rds = Redis.from_existing_index(
    embeddings,
    index_name = INDEX_NAME,
    schema = "redis_schema_kws.yaml",
    redis_url = "redis://10.0.1.21:6379",
)

returned_docs_mmr = rds.max_marginal_relevance_search(question, k=3, fetch_k=3, lambda_mult=0.8)
```

The returned error message is: `NotImplementedError:`

Could you provide additional information on your ETA to have MMR search implemented in Redis?

### Expected behavior

Retrieve the Document objects.