delayedkarma/langchain-issues huggingface dataset:
`RetrievalQA` and `HuggingFacePipeline` lead to `TypeError: cannot pickle '_thread.lock' object`

### System Info

Ubuntu 20.04.6
Python 3.8.5
Langchain 0.0.184

### Who can help?

_No response_

### Information

- [ ] The official example notebooks/scripts
- [X] My own modified scripts

### Related Components

- [X] 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 torch
from langchain.vectorstores import Qdrant
from langchain.embeddings import HuggingFaceInstructEmbeddings
from langchain.chains import RetrievalQA
from langchain.llms import HuggingFacePipeline
from transformers import (
    AutoModelForCausalLM,
    AutoTokenizer,
    pipeline,
    TextIteratorStreamer,
)

# embeddings 

embeddings_model_name = "hkunlp/instructor-base"

embeddings_model = HuggingFaceInstructEmbeddings(
    model_name=embeddings_model_name,
    model_kwargs={"device": "cuda"},
)

contents = ["bla", "blabla", "blablabla"]

vector_store = Qdrant.from_texts(
    contents,
    embeddings_model,
    location=":memory:",
    collection_name="test",
)

retriever = vector_store.as_retriever()

# llm

chatbot_model_name = ""togethercomputer/RedPajama-INCITE-Chat-3B-v1"

model = AutoModelForCausalLM.from_pretrained(
    chatbot_model_name,
    load_in_8bit=True,
    torch_dtype=torch.float16,
    device_map="auto",
)

tokenizer = AutoTokenizer.from_pretrained(chatbot_model_name)

streamer = TextIteratorStreamer(
    tokenizer,
    timeout=10.0,
    skip_prompt=True,
    skip_special_tokens=True,
)

pipe = pipeline(
    "text-generation",
    model=model,
    tokenizer=tokenizer,
    streamer=streamer,
    max_length=1024,
    temperature=0,
    top_p=0.95,
    repetition_penalty=1.15,
)

pipe = HuggingFacePipeline(pipeline=pipe)

# qa

qa = RetrievalQA.from_chain_type(
    llm=pipe,
    chain_type="stuff",
    retriever=retriever,
    return_source_documents=False,
)

qa.run("What is the capital of France")
```
which lead to 

```python
TypeError: cannot pickle '_thread.lock' object
````


### Expected behavior

I should be able to get the `streamer` outputs
Add maximal relevance search to SKLearnVectorStore
Labels: name: lgtm

# Add maximal relevance search to SKLearnVectorStore

This PR implements the maximum relevance search in SKLearnVectorStore. 

Twitter handle: jtolgyesi (I submitted also the original implementation of SKLearnVectorStore)

## Before submitting

Unit tests are included.

## Who can review?

Community members can review the PR once tests pass. Tag maintainers/contributors who might be interested:

  @hwchase17 - project lead

  VectorStores / Retrievers / Memory
  - @dev2049
parse_json_markdown is unable to parse json strings with nested triple backticks

### System Info

Langchain version 0.0.184, python 3.9.13
Function `parse_json_markdown` in langchain/output_parsers/json.py fails with input text string:
\`\`\`json
{
    "action": "Final Answer",
    "action_input": "Here's a Python script to remove backticks at the beginning and end of a string:\n\n\`\`\`python\ndef remove_backticks(s):\n    return s.strip('\`')\n\nstring_with_backticks = '\`example string\`'\nresult = remove_backticks(string_with_backticks)\nprint(result)\n\`\`\`\n\nThis script defines a function called \`remove_backticks\` that takes a string as input and returns a new string with backticks removed from the beginning and end. It then demonstrates how to use the function with an example string."
}
\`\`\`

Potential case of error:
`match.group(2)` in the function `parse_json_markdown` contains only the string up to the first occurrence of the second triple backticks:

{
    "action": "Final Answer",
    "action_input": "Here's a Python script to remove backticks at the beginning and end of a string:\n\n


### 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
- [X] Output Parsers
- [ ] Document Loaders
- [ ] Vector Stores / Retrievers
- [ ] Memory
- [X] Agents / Agent Executors
- [ ] Tools / Toolkits
- [ ] Chains
- [ ] Callbacks/Tracing
- [ ] Async

### Reproduction

Called function `parse_json_markdown` in langchain/output_parsers/json.py with input text string:
\`\`\`json
{
    "action": "Final Answer",
    "action_input": "Here's a Python script to remove backticks at the beginning and end of a string:\n\n\`\`\`python\ndef remove_backticks(s):\n    return s.strip('\`')\n\nstring_with_backticks = '\`example string\`'\nresult = remove_backticks(string_with_backticks)\nprint(result)\n\`\`\`\n\nThis script defines a function called \`remove_backticks\` that takes a string as input and returns a new string with backticks removed from the beginning and end. It then demonstrates how to use the function with an example string."
}
\`\`\`

### Expected behavior

Function `parse_json_markdown` should return the following json string
{
"action": "Final Answer",
"action_input": "Here's a Python script to remove backticks at the beginning and end of a string:\n\n\`\`\`python\ndef remove_backticks(s):\n return s.strip('\`')\n\nstring_with_backticks = '\`example string\`'\nresult = remove_backticks(string_with_backticks)\nprint(result)\n\`\`\`\n\nThis script defines a function called \`remove_backticks\` that takes a string as input and returns a new string with backticks removed from the beginning and end. It then demonstrates how to use the function with an example string."
}
added n_threads functionality for gpt4all

# Added support for modifying the number of threads in the GPT4All model

I have added the capability to modify the number of threads used by the GPT4All model. This allows users to adjust the model's parallel processing capabilities based on their specific requirements.

## Changes Made
- Updated the `validate_environment` method to set the number of threads for the GPT4All model using the `values["n_threads"]` parameter from the `GPT4All` class constructor.

## Context
Useful in scenarios where users want to optimize the model's performance by leveraging multi-threading capabilities. 
Please note that the `n_threads` parameter was included in the `GPT4All` class constructor but was previously unused. This change ensures that the specified number of threads is utilized by the model .

## Dependencies
There are no new dependencies introduced by this change. It only utilizes existing functionality provided by the GPT4All package.

## Testing
Since this is a minor change testing is not required.

## Who can review?
Community members can review the PR once tests pass. Tag maintainers/contributors who might be interested:

  Models
  - @hwchase17
  - @agola11
Change _parse_input implementation in BaseTool
Labels: name: auto:improvement

- Change to respect the BaseModel more than the results of the agent.

# Change _parse_input implementation in BaseTool

It's hard for me to figure out the intent of the original author of the old code. The original code tends to prioritize the agent's output over the results of pydantic's BaseModel parse_obj. For example, the old code does not honor pydantic's default value or alias. (If they are not included in the key of the agent's output, they are removed.) I was a bit curious about why this implementation was needed, so I created a pull request.

<!-- Remove if not applicable -->

Fixes # (issue)

## Before submitting

<!-- If you're adding a new integration, please include:

1. a test for the integration - favor unit tests that does not rely on network access.
2. an example notebook showing its use


See contribution guidelines for more information on how to write tests, lint
etc:

https://github.com/hwchase17/langchain/blob/master/.github/CONTRIBUTING.md
-->

## Who can review?

Community members can review the PR once tests pass. Tag maintainers/contributors who might be interested:
@vowelparrot
Rename and fix typo in lancedb
Labels: name: lgtm

# Fix typo in LanceDB notebook filename

<!--
Thank you for contributing to LangChain! Your PR will appear in our release under the title you set. Please make sure it highlights your valuable contribution.

Replace this with a description of the change, the issue it fixes (if applicable), and relevant context. List any dependencies required for this change.

After you're done, someone will review your PR. They may suggest improvements. If no one reviews your PR within a few days, feel free to @-mention the same people again, as notifications can get lost.

Finally, we'd love to show appreciation for your contribution - if you'd like us to shout you out on Twitter, please also include your handle!
-->


## Before submitting

<!-- If you're adding a new integration, please include:

1. a test for the integration - favor unit tests that does not rely on network access.
2. an example notebook showing its use


See contribution guidelines for more information on how to write tests, lint
etc:

https://github.com/hwchase17/langchain/blob/master/.github/CONTRIBUTING.md
-->

## Who can review?

Community members can review the PR once tests pass. Tag maintainers/contributors who might be interested:

<!-- For a quicker response, figure out the right person to tag with @

  @hwchase17 - project lead

  Tracing / Callbacks
  - @agola11

  Async
  - @agola11

  DataLoaders
  - @eyurtsev

  Models
  - @hwchase17
  - @agola11

  Agents / Tools / Toolkits
  - @vowelparrot

  VectorStores / Retrievers / Memory
  - @dev2049

 -->
SQLDatabaseToolkit doesn't work well with Postgresql, it will truncate the last double quotation marks in the SQL

### System Info

Langchain: 0.0.184
Python: 3.10.9
Platform: Windows 10 with Jupyter lab

### Who can help?

@vowelparrot

### Information

- [ ] The official example notebooks/scripts
- [X] 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
- [X] Tools / Toolkits
- [ ] Chains
- [ ] Callbacks/Tracing
- [ ] Async

### Reproduction

SQLDatabaseToolkit works well if the SQL doesn't include the double quotation marks at the end, if there is, it will truncate the last double quotation marks, resulting in an endless loop.
Below is the initial code snapshot.
![image](https://github.com/hwchase17/langchain/assets/38554198/6a444508-4774-4962-8ae2-e5513c756535)
And when I executed it.
![image](https://github.com/hwchase17/langchain/assets/38554198/5d3c76fe-8151-4caf-9970-03c84473f925)
The LLM generates the correct SQL, but the toolkit truncats the last double quotation marks.

### Expected behavior

Won't truncate the last double quotation marks for PostgreSql.
Issue: How to merge two vector in HNSWLib

### Issue you'd like to raise.


I try, but don't work.

my code:

```
    let { HNSWLib } = await import('langchain/vectorstores/hnswlib')
    let { OpenAIEmbeddings } = await import('langchain/embeddings/openai')

    let vectors1 = await HNSWLib.load(
        "D:/workcode/nodejs/chatgpt_server/vectors/32202",
        new OpenAIEmbeddings()
    )
    
    let vectors2 = await HNSWLib.load(
        "D:/workcode/nodejs/chatgpt_server/vectors/60551",
        new OpenAIEmbeddings()
    )
    
    let vectors3 = await vectors1.addVectors(vectors2, vectors2.docstore._docs)
```


### Suggestion:

_No response_
Add AzureCosmosDBVectorSearch VectorStore

### Feature request

Azure Cosmos DB for MongoDB vCore enables users to efficiently store, index, and query high dimensional vector data stored directly in Azure Cosmos DB for MongoDB vCore. It contains similarity measures such as COS (cosine distance), L2 (Euclidean distance) or IP (inner product) which measures the distance between the data vectors and your query vector. The data vectors that are closest to your query vector are the ones that are found to be most similar semantically and retrieved during query time. The accompanying PR would add support for Langchain Python users to store vectors from document embeddings generated from APIs such as Azure OpenAI Embeddings or Hugging Face on Azure.

[Azure Cosmos DB for MongoDB vCore](https://learn.microsoft.com/en-us/azure/cosmos-db/mongodb/vcore/vector-search)

### Motivation

This capability described in the feature request is currently not available for Langchain Python.

### Your contribution

I will be submitting a PR for this feature request.
Issue: Unsupported OpenAI-Version header provided: 2023-05-15. (HINT: you can provide any of the following support ed versions: 2020-10-01, 2020-11-07.'

### Issue you'd like to raise.

My code：
```
from langchain.embeddings.openai import OpenAIEmbeddings

    embeddings = OpenAIEmbeddings(
        openai_api_base='https://api.openai.com/v1',
        openai_api_type='open_ai',
        model='text-embedding-ada-002',
        openai_api_version='2023-05-15',
        openai_api_key=openai_api_key,
        max_retries=3,
    )
```

And I got `2023-05-30 07:28:40,163 INFO error_code=None error_message='Unsupported OpenAI-Version header provided: 2023-05-15. (HINT: you can provide any of the following supported versions: 2020-10-01, 2020-11-07. Alternatively, you can simply omit this header to use the default version associated with your account.)' error_param=headers:openai-version error_type=invalid_request_error message='OpenAI API error received' stream_error=False
`

Why this is supported versions so old (they are 2020-10-01, 2020-11-07)? Is this normal ?
Anybody got this error ?

### Suggestion:

_No response_
Is it possible to return similarity score from RetrievalQA/docsearch

### Feature request

It will be very nice to have similarity score from docsearch.
Now I have list of documents even if model says "I'm sorry, but I don't have enough information to answer your question".

```
from langchain.chains import RetrievalQA

qa = RetrievalQA.from_chain_type(
    llm=llm,
    chain_type= "stuff", 
    retriever = docsearch.as_retriever(
        search_type="similarity",
        search_kwargs={"k":3}
    ),
    return_source_documents=True
)
```

### Motivation

Now it returns list of documents even if model says "I'm sorry, but I don't have enough information to answer your question."
And also I got list of not really relevant documents.

### Your contribution

Not sure here. For example in `chroma.py`  I can add output of similarity:

```
    def similarity_search(
        self,
        query: str,
        k: int = DEFAULT_K,
        filter: Optional[Dict[str, str]] = None,
        **kwargs: Any,
    ) -> List[Document]:
        docs_and_scores = self.similarity_search_with_score(query, k, filter=filter)
        result = []
        for doc, score in docs_and_scores:
          doc.metadata['score'] = score
          result.append(doc)
        return result
```

**BUT** it's not relevant to the output - I got similarity 0.3-0.4 for correct answers and at the same time - for "he context does not provide any information about what...". So this method is good to return score, but not good to solve all my questions.
Chroma integration improvement
Labels: name: area: vector store, name: auto:enhancement

# Chroma Integration Improvement 
 [Langchain love](https://github.com/chroma-core/chroma/issues/560): deepened the integration of langchain and chromadb.
 

- [x] upsert
- [x] delete
- [x] get_all_ids
- [x] docstrings improvement
- [x] Examples


<!-- Remove if not applicable -->

Fixes # (issue)
- #3011 
- #1714 



## Who can review?

- @dev2049
- @jeffchuber
docs: cleaning

# docs cleaning

Changed docs to consistent format (probably, we need an official doc integration template):
- ClearML - added product descriptions; changed title/headers
- Rebuff  - added product descriptions; changed title/headers
- WhyLabs  - added product descriptions; changed title/headers
- Docugami - changed title/headers/structure
- Airbyte - fixed title
- Wolfram Alpha - added descriptions, fixed title
- OpenWeatherMap -  - added product descriptions; changed title/headers
- Unstructured - changed description

## Who can review?

Community members can review the PR once tests pass. Tag maintainers/contributors who might be interested:

@hwchase17
@dev2049
Early Stopping Exception

### Feature request

It would be useful to introduce an EarlyStoppingException for capture by the AgentExecutor. 

### Motivation

It would be nice to throw a `EarlyStoppingException` in a tool used by an Agent when certain pre-conditions are met (e.g. a validation of something has failed). The `EarlyStoppingException` would be caught by the AgentExector where it would immediately return the error message of the tool as the output.

My current work around to achieve something like this without customising the AgentExecutor  requires me to throw the error message as part of the JSON output of the tool in the output format the agent expects from the tool. The agent would then take this information and run it through an LLM. This is not as ideal as an immediate return of the error message as the LLM doesn't return the exact message and it has to pass through a LLM again. 

The `return_immediate_results` is not ideal in this case as I would like the Agent to summarise the output of the tool on most passes, except when the condition is met where a `EarlyStoppingException` is thrown and caught by the `AgentExector`.

### Your contribution

Happy to create a PR for this if it is wanted.
DocumentLoader for GitHub
Labels: name: enhancement, name: lgtm, name: area: doc loader

# Creates GitHubLoader (#5257)

GitHubLoader is a DocumentLoader that loads issues and PRs from GitHub.

Fixes #5257

Community members can review the PR once tests pass. Tag maintainers/contributors who might be interested:
DataLoaders
- @eyurtsev

Twitter: [@UmerHAdil](https://twitter.com/@UmerHAdil) | Discord: RicChilligerDude#7589
add idea of foreign_id to enable easier langchain-vector store intera…
Labels: name: area: vector store, name: auto:improvement

@dev2049 @hwchase17 - what do you all think about add a `foreign_id` to `Document`. 

See the test for Update included here is included to demonstrate why this is useful. 

It enables users to pass lists of `Documents` to vector store operations like `update`, `delete`, etc and handle the location of those records correctly. 

This is set up so that if the user sets the `foreign_id` before adding the records to the database, the database will use those `foreign_id`s as the ids. 

*** 

Concerns
- the name `foreign_id` implies that it is not something the user should set, where the user setting it is valid.
- if the user changes `foreign_id` after it has been passed to the database, the "link" will be lost. 
- I am not entirely familiar with the lifecycle of `Documents` inside LangChain and I don't know if this makes sense. 

The alternative to adding a `foreign_id` would be to match on the `page_content` - but I think this is far worse.


***

I couldn't get tests to run locally. Perhaps someone can point me in the right direction.
Adds the option to pass the original prompt into the AgentExecutor for PlanAndExecute agents

# Adds the option to pass the original prompt into the AgentExecutor for PlanAndExecute agents

This PR allows the user to optionally specify that they wish for the original prompt/objective to be passed into the Executor agent used by the PlanAndExecute agent. This solves a potential problem where the plan is formed referring to some context contained in the original prompt, but which is not included in the current prompt. 

Currently, the prompt format given to the Executor is:
```
System: Respond to the human as helpfully and accurately as possible. You have access to the following tools:

<Tool and Action Description>

<Output Format Description>

Begin! Reminder to ALWAYS respond with a valid json blob of a single action. Use tools if necessary. Respond directly if appropriate. Format is Action:```$JSON_BLOB```then Observation:.
Thought:
Human: <Previous steps>

<Current step>
```

This PR changes the final part after `Human:` to optionally insert the objective:
```
Human: <objective>

<Previous steps>

<Current step>
```

I have given a specific example in #5400 where the context of a database path is lost, since the plan refers to the "given path".

The PR has been linted and formatted. So that existing behaviour is not changed, I have defaulted the argument to `False` and added it as the last argument in the signature, so it does not cause issues for any users passing args positionally as opposed to using keywords.

Happy to take any feedback or make required changes! 

Fixes #5400

## Who can review?

Community members can review the PR once tests pass. Tag maintainers/contributors who might be interested:
@vowelparrot
Add the ability to pass the prompt through to Executor Agents for enrichment during PlanAndExecute

### Feature request

Add the ability to pass the original prompt through to the ExecutorAgent so that the original explicit context is not lost during a PlanAndExecute run.

### Motivation

PlanAndExecute agents can create a plan of steps dependent on context given in the original prompt. However, this context is lost after the plan is created and is being executed.

However, often the plan is formed in a way which refers to the prior context, losing information. For example, I gave the following prompt, and gave the agent access only to the PythonREPL tool:
```py
prompt = (
    f"Task: Analyse the customer data available in the database with path '{db_path}'. Tell me the average "
    "sales by month."
)
```
In the above example, `db_path` is a fully formed string which can be passed directly to `sqlalchemy.create_engine`. 

The first step in the plan formed was: `Connect to the database using the given path`. This would ordinarily be fine, however, the context of the "given path" was lost, as it was not part of the reformed prompt passed to the executor. Optionally including the original prompt in the template should assist with this.

### Your contribution

I will be submitting a PR shortly with a proposed solution :)
GraphCypherQAChain Authentication error

### System Info

langchain   0.0.183 , Platform  Anaconda, Python version  3.10.9
![Capture](https://github.com/hwchase17/langchain/assets/42122075/b09e3f03-d63a-4aa6-94bf-79722f2118ab)


### Who can help?

@hwchase17 
 

### 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
- [X] Chains
- [X] Callbacks/Tracing
- [ ] Async

### Reproduction

[issue.txt](https://github.com/hwchase17/langchain/files/11591485/issue.txt)


### Expected behavior

Cypher Query along with Explanation
convert the parameter 'text' to uppercase in the function 'parse' of the class BooleanOutputParser
Labels: name: lgtm

when the LLMs output 'yes|no'，BooleanOutputParser can parse it to 'True|False', fix the ValueError in parse().
<!--
when use the BooleanOutputParser in the chain_filter.py, the LLMs output 'yes|no'，the function 'parse' will throw ValueError。
-->

Fixes # (issue)
  #5396
  https://github.com/hwchase17/langchain/issues/5396


@hwchase17