delayedkarma/langchain-issues huggingface dataset:
Issue: Installing langchain[llms] is really difficult
Labels: name: bug, name: documentation, name: needs documentation

### Issue you'd like to raise.

I tried to install langchain[llms] with pip on Windows 11. The installation did not throw any errors. But trying to import langchain in a python script gives the following error:
from numexpr.interpreter import MAX_THREADS, use_vml, __BLOCK_SIZE1__
ImportError: DLL load failed while importing interpreter: The specified module could not be found.

pip list shows that numexpr=2.8.4 is installed.
Uninstalling and reinstalling numexpr did not help.
Since I had a machine where langchain was working I could determine the difference that the one machine had Visual Studio installed with C compiling capabilities.
Uninstalling and reinstalling numexpr fixed it after installing Visual Studio on the second machine.

But since the documentation does not explain that Visual Studio is required in Windows I am confused and it took me a while to figure this out. Also that the installation had no errors but still didnt worked? Maybe someone looks into that.

Please delete the issue if this is not the right place.

### Suggestion:

_No response_
Callbacks for retriever
Labels: name: enhancement

### Feature request

Have callbacks as an argument for BaseConversationalRetrievalChain._get_docs method and BaseRetriever.get_relevant_documents

### Motivation

I am using a custom retriever which has multiple intermediate steps, and I would like to store info from some of these steps for debugging and subsequent analyses. This information is specific to the request, and it cannot be stored at an individual document level.

### Your contribution

I think this can be addressed by having an option to pass callbacks to the BaseConversationalRetrievalChain._get_docs method and BaseRetriever.get_relevant_documents. BaseCallbackHandler may have to be modified too to extend a new class RetrieverManagerMixin which can contain methods like on_retriever_start and on_retriever_end.
Fix Document Similarity Check with passed Threshold
Labels: name: lgtm

Converting the Similarity obtained in the similarity_search_with_score_by_vector method whilst comparing to the passed 
threshold. This is because the passed threshold is a number between 0 to 1 and is already in the relevance_score_fn format. 
As of now, the function is comparing two different scoring parameters and that wouldn't work.

Dependencies
None

Issue:
Different scores being compared in similarity_search_with_score_by_vector method in FAISS.

Tag maintainer
@hwchase17



<!-- Thank you for contributing to LangChain!

Replace this 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!

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.

Maintainer responsibilities:
  - General / Misc / if you don't know who to tag: @dev2049
  - DataLoaders / VectorStores / Retrievers: @rlancemartin, @eyurtsev
  - Models / Prompts: @hwchase17, @dev2049
  - Memory: @hwchase17
  - Agents / Tools / Toolkits: @vowelparrot
  - Tracing / Callbacks: @agola11
  - Async: @agola11

If no one reviews your PR within a few days, feel free to @-mention the same people again.

See contribution guidelines for more information on how to write/run tests, lint, etc: https://github.com/hwchase17/langchain/blob/master/.github/CONTRIBUTING.md
 -->
feat: Add `UnstructuredOrgModeLoader`

### Summary

Adds `UnstructuredOrgModeLoader` for processing [Org-mode](https://en.wikipedia.org/wiki/Org-mode) documents.

### Testing

```python
from langchain.document_loaders import UnstructuredOrgModeLoader

loader = UnstructuredOrgModeLoader(
    file_path="example_data/README.org", mode="elements"
)
docs = loader.load()
print(docs[0])
```

### Reviewers

- @rlancemartin
- @eyurtsev
- @hwchase17
Support for Pydantic v2
Labels: name: enhancement

### Feature request

Currently, `langchain 0.0.217 depends on pydantic<2 and >=1`. Pydantic v2 is re-written in Rust and is between 5-50x faster than v1 depending on the use case. Given how much LangChain relies on Pydantic for both modeling and functional components, and given that FastAPI is now supporting (in beta) Pydantic v2, it'd be great to see LangChain handle a user-specified installation of Pydantic above v2. 

The following is an example of what happens when a user specifies installing Pydantic above v2. 

```bash
The conflict is caused by:
    The user requested pydantic==2.0b2
    fastapi 0.100.0b1 depends on pydantic!=1.8, !=1.8.1, <3.0.0 and >=1.7.4
    inflect 6.0.4 depends on pydantic>=1.9.1
    langchain 0.0.217 depends on pydantic<2 and >=1
```

### Motivation

Pydantic v2 is re-written in Rust and is between 5-50x faster than v1 depending on the use case. Given how much LangChain relies on Pydantic for both modeling and functional components, and given that FastAPI is now supporting (in beta) Pydantic v2, it'd be great to see LangChain handle a user-specified installation of Pydantic above v2. 

### Your contribution

Yes! I'm currently opening just an issue to document my request, and because I'm fairly backlogged. But I have contributed to LangChain in the past and would love to write a pull request to facilitate this in full.
WhatsappChatLoader doesn't ignore deleted messages and omitted media 
Labels: name: bug, name: enhancement

### System Info

langchain git+https://github.com/hwchase17/langchain@8392ca602c03d3ae660d05981154f17ee0ad438e 
Archcraft x86_64
Python 3.11.3

### Who can help?

@eyurtsev @dev2049 

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

1.  Export the chat from WhatsApp, of a conversation with media and deleted messages.
2. The exported chat contains deleted messages and omitted media during the export. For example :  `6/29/23, 12:16 am - User 4: This message was deleted` and `4/20/23, 9:42 am - User 3: <Media omitted>`.  
3. Currently these messages are also processed and stored in the index.

### Expected behavior

We can avoid embedding these  messages in the index.
Issue: Large observation handling limit
Labels: name: enhancement, name: question

### Large observation handling limit.

Hey langchain community,

I have a tool which takes a database query as input and does database query. This is similar to what `QuerySQLDataBaseTool` does. The problem is the output of the query is out of control, it can be large and the agent exceeded the token limit.

The solution I have tried:
1. Do pagination:
    - Chunk the large output, summarize each chunk according to the target question
    - Combine all chunks' summarization, which is much smaller than the original output.

    Problems: 
    - Even though I did the summarization according to the target question, the summarization will still lose information.
    - The pagination can be slow.

2. Vectorization:
    - Chunk the large output
    - Embed each chunk and put them into a Vector DB.
    - Do a similarity search based on the target question, and take number of chunks within the token limit.

    Problems:
    - The embedding take times, so it can be slow for a single thought.
    - The output of the query is semantic continuously as a a whole, the chunks can break the semantic meaning.

Does anyone have a solution for this problem? I appreciated any idea! 

### Suggestion:

_No response_
Implement Function Callback tracer

Description: I wanted to be able to redirect debug output to a function, but it wasn't very easy. I figured it would make sense to implement a `FunctionCallbackHandler`, and reimplement `ConsoleCallbackHandler` as a subclass that calls the `print` function. Now I can create a simple subclass in my project that calls `logging.info` or whatever I need.

Tag maintainer: @agola11
Twitter handle: `@andandaraalex`
Create MultiQueryRetriever

Distance-based vector database retrieval embeds (represents) queries in high-dimensional space and finds similar embedded documents based on "distance". But, retrieval may produce difference results with subtle changes in query wording or if the embeddings do not capture the semantics of the data well. Prompt engineering / tuning is sometimes done to manually address these problems, but can be tedious.

The `MultiQueryRetriever` automates the process of prompt tuning by using an LLM to generate multiple queries from different perspectives for a given  user input query. For each query, it retrieves a set of relevant documents and takes the unique union across all queries to get a larger set of potentially relevant documents. By generating multiple perspectives on the same question, the `MultiQueryRetriever` might be able to overcome some of the limitations of the distance-based retrieval and get a richer set of results.
rail_parser: Allow creation from pydantic

<!-- Thank you for contributing to LangChain!

Replace this 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!

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.

Maintainer responsibilities:
  - General / Misc / if you don't know who to tag: @dev2049
  - DataLoaders / VectorStores / Retrievers: @rlancemartin, @eyurtsev
  - Models / Prompts: @hwchase17, @dev2049
  - Memory: @hwchase17
  - Agents / Tools / Toolkits: @vowelparrot
  - Tracing / Callbacks: @agola11
  - Async: @agola11

If no one reviews your PR within a few days, feel free to @-mention the same people again.

See contribution guidelines for more information on how to write/run tests, lint, etc: https://github.com/hwchase17/langchain/blob/master/.github/CONTRIBUTING.md
 -->

Adds a way to create the guardrails output parser from a pydantic model.
PostgresChatMessageHistory message order isn't guaranteed
Labels: name: bug

### System Info

Langchain version: 0.0.208
OS version: macOS 13.4
Python version: 3.10.12

### Who can help?

@hwchase17

### Information

- [ ] The official example notebooks/scripts
- [X] 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

Queries without an `order by` clause aren't guaranteed to have any particular order. 

### Expected behavior

Chat history should be in order.
Custom tool class not working with extra properties
Labels: name: bug, name: question

### System Info

Hello everyone,

I am currently utilizing the OpenAIFunctions agent along with some custom tools that I've developed. I'm trying to incorporate a custom property named `source_documents` into one of these tools. My intention is to assign a value to this property within the tool and subsequently utilize this value outside of the tool.

To illustrate, this is how I invoke my custom tool: `tools = [JamesAllenRetrievalSearchTool(source_documents), OrderTrackingTool()]`. Here, `source_documents `is the property that I wish to update within the `JamesAllenRetrievalSearchTool `class.

I attempted to create a constructor within the custom tool and pass the desired variable for updating, but unfortunately, this approach was unsuccessful. If anyone has knowledge of a solution to my problem, I would greatly appreciate your assistance.

Thank you!

### 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
- [X] Tools / Toolkits
- [x] Chains
- [ ] Callbacks/Tracing
- [ ] Async

### Reproduction

Here is My custom tool Class: 

`class JamesAllenRetrivalSearchTool(BaseTool):

    name = "jamesallen-search"
    description = "Use this tool as the primary source of context information. Always search for the answers using this tool first, don't make up answers yourself"
    return_direct = True
    args_schema: Type[BaseModel] = JamesAllenRetrivalSearchInput  

    def _run(self, question: str, run_manager: Optional[CallbackManagerForToolRun] = None) -> str:
        knowledge_base_retrival_chain = RetrivalQAChain(prompt)
        result = knowledge_base_retrival_chain.run(question)
        # **HERE -> I need to update returned source_documents from the chain outside the custom tool class**
        # source_documents = result["source_documents"]
        # self.retrival_source_docs = source_documents
        return result["result"]
    
    async def _arun(self, question: str, run_manager: Optional[AsyncCallbackManagerForToolRun] = None) -> str:
        """Use the tool asynchronously."""
        raise NotImplementedError("Not implemented")
`

### Expected behavior

When I run the tool I expect that the answer from the chain will return and the source documents will be update.
Use serialized format for messages in tracer

<!-- Thank you for contributing to LangChain!

Replace this 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!

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.

Maintainer responsibilities:
  - General / Misc / if you don't know who to tag: @dev2049
  - DataLoaders / VectorStores / Retrievers: @rlancemartin, @eyurtsev
  - Models / Prompts: @hwchase17, @dev2049
  - Memory: @hwchase17
  - Agents / Tools / Toolkits: @vowelparrot
  - Tracing / Callbacks: @agola11
  - Async: @agola11

If no one reviews your PR within a few days, feel free to @-mention the same people again.

See contribution guidelines for more information on how to write/run tests, lint, etc: https://github.com/hwchase17/langchain/blob/master/.github/CONTRIBUTING.md
 -->
Import Error for Gpt4All
Labels: name: bug

### System Info

Langchain version: 0.0.27 (I installed over pip install lanchain)
Python v: 3.8
OS: Windows 11

When I try to ``from langchain.llms import GPT4All`

I am getting the error that says there is no Gpt4All module.
When I check the installed library it does not exist. However when I check github repo it exist in the latest version as per today.

### Who can help?

_No response_

### 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
- [ ] Agents / Agent Executors
- [ ] Tools / Toolkits
- [ ] Chains
- [ ] Callbacks/Tracing
- [ ] Async

### Reproduction

```
from langchain.llms import GPT4All

model_path = r"C:\Users\suat.atan\AppData\Local\nomic.ai\GPT4All\ggml-gpt4all-j-v1.3-groovy.bin"
llm = GPT4All(model= model_path)

llm("Where is Paris?")
```

### Expected behavior

At least the first line of the code should work.
This code should answer my prompt
WebBaseLoader: optionally raise exception in the case of http error

  - **Description**: this PR adds the possibility to raise an exception in the case the http request did not return a 2xx status code. This is particularly useful in the situation when the url points to a non-existent web page, the server returns a http status of 404 NOT FOUND, but WebBaseLoader anyway parses and returns the http body of the error message.
  - **Dependencies**: none,
  - **Tag maintainer**: @rlancemartin, @eyurtsev,
  - **Twitter handle**: jtolgyesi
"office365/__init__ .py" filename contains typo
Labels: name: bug

### System Info

Most recent version of langchain, 0.0.216.

### 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

Causes bazel build fail due to small typo in __init__.py filename (filenames cannot have spaces).

### Expected behavior

Should rename __init__. py to __init__.py
Synchronize metadata types between pgvector.add_texts() and pgvector.similarity_search_with_score_by_vector()
Labels: name: area: vector store, name: auto:bug

…similarity_search_with_score_by_vector()

pgvector.add_texts() stored metadata to postgresql is from dict to string, but pgvector.similarity_search_with_score_by_vector() get metadata just string from database, when struct Document object, report error:
```
pydantic.error_wrappers.ValidationError: 1 validation error for Document
metadata
  value is not a valid dict (type=type_error.dict)
```
LLMRouterChain uses deprecated predict_and_parse method
Labels: name: bug, name: needs work

### System Info

langchain v0.0.216, Python 3.11.3 on WSL2

### Who can help?

@hwchase17 

### Information

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

### Related Components

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

### Reproduction

Follow the first example at https://python.langchain.com/docs/modules/chains/foundational/router

### Expected behavior

[This line](https://github.com/hwchase17/langchain/blob/v0.0.216/langchain/chains/llm.py#L275) gets triggered:

> The predict_and_parse method is deprecated, instead pass an output parser directly to LLMChain.

As suggested by the error, we can make the following code changes to pass the output parser directly to LLMChain by changing [this line](https://github.com/hwchase17/langchain/blob/v0.0.216/langchain/chains/router/llm_router.py#L83) to this:

```python
llm_chain = LLMChain(llm=llm, prompt=prompt, output_parser=prompt.output_parser)
```

And calling `LLMChain.__call__` instead of `LLMChain.predict_and_parse` by changing [these lines](https://github.com/hwchase17/langchain/blob/v0.0.216/langchain/chains/router/llm_router.py#L58-L61) to this:

```python
cast(
    Dict[str, Any],
    self.llm_chain(inputs, callbacks=callbacks),
)
```

Unfortunately, while this avoids the warning, it creates a new error:

> ValueError: Missing some output keys: {'destination', 'next_inputs'}

because LLMChain currently [assumes the existence of a single `self.output_key`](https://github.com/hwchase17/langchain/blob/v0.0.216/langchain/chains/llm.py#L220) and produces this as output:

> {'text': {'destination': 'physics', 'next_inputs': {'input': 'What is black body radiation?'}}}

Even modifying that function to return the keys if the parsed output is a dict triggers the same error, but for the missing key of "text" instead. `predict_and_parse` avoids this fate by skipping output validation entirely.

It appears changes may have to be a bit more involved here if LLMRouterChain is to keep using LLMChain.
Batch search for Qdrant database
Labels: name: enhancement

### Feature request

I am proposing an enhancement for the `langchain` implementation of `qdrant`. As of the current version, `langchain` only supports single text searches. My feature proposal involves extending `langchain` to integrate the [search_batch](https://github.com/qdrant/qdrant-client/blob/master/qdrant_client/qdrant_client.py#L171) method from the `qdrant` client. This would allow us to conduct batch searches, increasing efficiency, and potentially speeding up the process for large volumes of text.

### Motivation

This feature request is born out of the need for more efficient text searches when dealing with large data sets. Currently, using `langchain` for search functionality becomes cumbersome and time-consuming due to the lack of batch search capabilities. Running single text searches one after another restricts the speed of operations and is not scalable when dealing with large text corpuses.

Given the increasing size and complexity of modern text datasets and applications, it is more pertinent than ever to have a robust and efficient method of search that can handle bulk operations. With this enhancement, we can perform multiple text searches simultaneously, thus saving considerable time and computing resources.

### Your contribution

While I would love to contribute, I simply do not have the time right now, so I, therefore, hope that the great community, currently building `langchain` sees some sense in the above-mentioned paragraphs.