delayedkarma/langchain-issues huggingface dataset:
Using a self-hosted LLM in an offline environment
Labels: name: auto:bug, name: auto:question, name: area: models

### Issue you'd like to raise.

I built a self-hosted LLM and applied Langchain's HuggingFaceTextGenInference for use in an offline environment, but an error occurred because the tokenizer was forced to call online in the code using the map_reduce type of summarize_chain.

I would like to solve this problem to use self-hosted LLM in an offline environment

The error message is as follows:

OSError: Can't load tokenizer for 'gpt2'. If you were trying to load it from 'https://huggingface.co/models', make sure you don't have a local directory with the same name. Otherwise, make sure 'gpt2' is the correct path to a directory containing all relevant files for a GPT2TokenizerFast tokenizer.
Output is truncated. View as a [scrollable element](command:cellOutput.enableScrolling?8199cda9-1c5c-4995-ba50-f58f326273c3) or open in a [text editor](command:workbench.action.openLargeOutput?8199cda9-1c5c-4995-ba50-f58f326273c3). Adjust cell output [settings](command:workbench.action.openSettings?%5B%22%40tag%3AnotebookOutputLayout%22%5D)...

### Suggestion:

I would like to know how to change the tokenizer used online in HuggingFaceTextGenInference to offline or how to utilize self-hosted LLM without using HuggingFaceTextGenInference.
[Issue#11595] Multithreading support for TextSplitter
Labels: name: auto:improvement

### Feature request

Add optional multithreading support for `TextSplitter`, e.g for the loop in `TextSplitter.create_documents`:

https://github.com/langchain-ai/langchain/blob/e2a9072b806b1a45b0e4c107b30dddd0f67a453f/libs/langchain/langchain/text_splitter.py#L138-L153


Question: Is there anything opposing this idea / preventing it from a  technical perspective?

### Motivation

Text splitting can take up significant time and resources if a custom length function is used to measure chunk length (e.g. based on a huggingface tokenizer's encode method), especially for the `RecursiveCharacterTextSplitter`.

Therefore we want to introduce multithreading support on a document level.

### Your contribution

Feature Request: https://github.com/langchain-ai/langchain/issues/11595
PR: https://github.com/langchain-ai/langchain/pull/11598
add new field
Labels: name: area: vector store, name: auto:improvement

<!-- 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/langchain-ai/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. It lives in `docs/extras` directory.

If no one reviews your PR within a few days, please @-mention one of @baskaryan, @eyurtsev, @hwchase17.
 -->
Multithreading support for TextSplitter
Labels: name: auto:question, name: auto:enhancement

### Feature request

Add optional multithreading support for `TextSplitter`, e.g for the loop in `TextSplitter.create_documents`:

https://github.com/langchain-ai/langchain/blob/e2a9072b806b1a45b0e4c107b30dddd0f67a453f/libs/langchain/langchain/text_splitter.py#L138-L153


Question: Is there anything opposing this idea / preventing it from a  technical perspective?

### Motivation

Text splitting can take up significant time and resources if a custom length function is used to measure chunk length (e.g. based on a huggingface tokenizer's encode method), especially for the `RecursiveCharacterTextSplitter`.

Therefore we want to introduce multithreading support on a document level.

### Your contribution

Feature Request: https://github.com/langchain-ai/langchain/issues/11595
PR: https://github.com/langchain-ai/langchain/pull/11598
fix: Change the docs of JSONAgentOutputParser
Labels: name: area: agent, 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/langchain-ai/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. It lives in `docs/extras` directory.

If no one reviews your PR within a few days, please @-mention one of @baskaryan, @eyurtsev, @hwchase17.
 -->
I am merely making some minor adjustments to the function documentation. I hope to provide a small assistance to LangChain.
  - **Description:** Change the docs of JSONAgentOutputParser. It will be `JSON` better,
  - **Issue:** no,
  - **Dependencies:** no,
  - **Tag maintainer:** @hwchase17,
  - **Twitter handle:** Not worth mentioning.
AzureOpenAI doesn't expose parameter to set custom HTTP headers.
Labels: name: area: embeddings, name: auto:improvement

### Feature request

Hey hi hello :)

Some organizations expose Azure OpenAI endpoints via some proxies that need additional HTTP headers. Currently AzureOpenAI class doesn't expose (at least I wasn't able to find one) a capability to set this. Similarly to what is possible in OpenAIEmbeddings ([https://api.python.langchain.com/en/latest/embeddings/langchain.embeddings.openai.OpenAIEmbeddings.html#langchain.embeddings.openai.OpenAIEmbeddings.headers](https://api.python.langchain.com/en/latest/embeddings/langchain.embeddings.openai.OpenAIEmbeddings.html#langchain.embeddings.openai.OpenAIEmbeddings.headers)). Something similar was already discussed ([https://github.com/langchain-ai/langchain/issues/2120](https://github.com/langchain-ai/langchain/issues/2120)) and embeddings have that already solved. It would be great to have that also for AzureOpenAI class.

### Motivation

I need this to get via proxy that needs additional HTTP headers.

### Your contribution

I don't think I can contribute to this.
Return ids for the document returned from the Similarity Search.
Labels: name: area: vector store, name: auto:improvement, name: integration: chroma

### Feature request

I want to get the ids of the document returned when performing `similarity_search()` or `similarity_search_with_score()`. The id should be present in the metadata = {"id": id}

  

### Motivation

Want to update the metadata of the documents that are returned in the similarity search. This update can only be done if the the documents returned has the id in its metadata. When adding the documents to the vectordb, I am not adding the ids, as they are automatically generated if not passed. 

### Your contribution

No contributions but below is the changes that can be made:

```
def _results_to_docs_and_scores(results: Any) -> List[Tuple[Document, float]]:
    return [
        # TODO: Chroma can do batch querying,
        # we shouldn't hard code to the 1st result
        (Document(page_content=result[0], metadata=(result[1] | {'id': result[3]}) or {}), result[2])
        for result in zip(
            results["documents"][0],
            results["metadatas"][0],
            results["distances"][0],
            results["ids"][0]
        )
    ]

```
Getting error "Just a moment...Enable JavaScript and cookies to continue" when loading website using WebBaseLoader
Labels: name: area: doc loader, name: auto:bug

### System Info

langchain==0.0.311

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

```
from langchain.document_loaders import WebBaseLoader
loader = WebBaseLoader("https://academyselfdefense.com/")
data = loader.load()
raw_text = data[0].page_content
print(raw_text)
```

### Expected behavior

load proper content in website instead of` Just a moment...Enable JavaScript and cookies to continue`
Request for BedrockChat async functions(BedrockChat.agenerate).
Labels: name: auto:enhancement, name: area: models

### Feature request

Is there any plan for supporting BedrockChat async calls?


### Motivation

I am using this api in a fastapi backend, while receiving data from bedrock I have to send data back to frontend. But for now the network is totally blocked, and streaming is no possible in this case.

### Your contribution

no
similarity_search_with_relevance_scores is not working properly with Pinecone
Labels: name: area: vector store, name: auto:bug, name: integration: pinecone

### System Info

Langchain Version: 0.0.311
Python: 3.10.9

### Who can help?

_No response_

### 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
- [X] Vector Stores / Retrievers
- [ ] Memory
- [ ] Agents / Agent Executors
- [ ] Tools / Toolkits
- [ ] Chains
- [ ] Callbacks/Tracing
- [ ] Async

### Reproduction

I loaded the my vector store from **pinecone** and try to find top-3 most similar documents with the relevance score
```
vectorstore = Pinecone(index, embed.embed_query, text_field)
answers = vectorstore.similarity_search_with_score(query, 3)
for item in answers:
    print(item[1]) # print out score
```
By running above code, I can get relevance score for those 3 documents:
```
0.851780415
0.851505935
0.850369573
```
It looks as expected

But when I try to use `similarity_search_with_relevance_scores` to find out similar docs:
```
answers= vectorstore.similarity_search_with_relevance_scores(query, score_threshold=0.8)
```
From my understanding it should return me at least 3 docs since we do have docs similar higher than 0.85, but I got warning `No relevant docs were retrieved using the relevance score threshold 0.8` with an empty return

And I tried vectorstore retriever as well and got same warning and empty return:
```
retriever = vectorstore.as_retriever(
    search_type="similarity_score_threshold",
    search_kwargs={"score_threshold": 0.8}
)
answer = retriever.get_relevant_documents(query)
print(answer)
```
Did I use the score function incorrectly ? If not, is there any other ways to query with score_threshold? 
Thanks





### Expected behavior

When using 
```
answers= vectorstore.similarity_search_with_relevance_scores(query, score_threshold=0.8)
```
or 
```
retriever = vectorstore.as_retriever(
    search_type="similarity_score_threshold",
    search_kwargs={"score_threshold": 0.8}
)
answer = retriever.get_relevant_documents(query)
print(answer)
```
It should return me few of doc that have >= 0.8 similarity.
Add dedicated `type` attribute to be used solely for serialization purposes
Labels: name: auto:improvement, name: area: models

Adds standard `type` field for all messages that will be serialized/validated by pydantic.

* The presence of `type` makes it easier for developers consuming schemas to write client code to serialize/deserialize.
* In LangServe `type` will be used for both validation and will appear in the generated openapi specs
Discord Integration Toolkit
Labels: name: area: agent, name: auto:enhancement

### Feature request

Introduce a comprehensive Discord Integration Toolkit to Langchain. This would allow a more seamless and direct interaction with the Discord API through an Agent interface. It should encompass capabilities like message dispatch, channel navigation, user role management, and channel administration.

### Motivation

At present, Langchain offers a limited set of functionalities for interfacing with the Discord API. Specifically, the available method is the DiscordChatLoader, necessitating manual data downloading and uploading in a CSV format. This approach not only lacks versatility but is cumbersome. Furthermore, there's an absence of functions that would empower an LLM Agent to undertake tasks like messaging, channel searches, role assignments, and channel handling on Discord.

### Your contribution

We are initiating the development phase for this proposal and intend to submit a PR once the feature reaches completion.
Fix CohereRerank configuration
Labels: name: auto:bug

**Description:** CohereRerank is missing `cohere_api_key` as a field and since extras are forbidden, it is not possible to pass-in the key.  The only way is to use an env variable named `COHERE_API_KEY`.

For example, if trying to create a compressor like this:
```python
cohere_api_key = "......Cohere api key......"
compressor = CohereRerank(cohere_api_key=cohere_api_key)
```
you will get the following error:
```
  File "/langchain/.venv/lib/python3.10/site-packages/pydantic/v1/main.py", line 341, in __init__
    raise validation_error
pydantic.v1.error_wrappers.ValidationError: 1 validation error for CohereRerank
cohere_api_key
  extra fields not permitted (type=value_error.extra)
```
Update docs to specify Indexing-API-compatible vectorstores
Labels: name: lgtm, name: area: vector store, name: auto:documentation

**Description:** Update Indexing API docs to specify vectorstores that are compatible with the Indexing API. I add a unit test to remind developers to update the documentation whenever they add or change a vectorstore in a way that affects compatibility. For the unit test I repurposed existing code from [here](https://github.com/langchain-ai/langchain/blob/v0.0.311/libs/langchain/langchain/indexes/_api.py#L245-L257).

This is my first PR to an open source project. This is a trivially simple PR whose main purpose is to make me more comfortable submitting Langchain PRs. If this PR goes through I plan to submit PRs with more substantive changes in the near future. 

**Issue:** Resolves [10482](https://github.com/langchain-ai/langchain/discussions/10482).

**Dependencies:** No new dependencies.

**Twitter handle:** None.
AmazonAPIGatewayEmbeddings class for text embeddings
Labels: name: area: embeddings, name: auto:enhancement, name: integration: aws

### Feature request

As of today, it's not possible to use Amazon API Gateway for exposing embeddings model and use it as part of a chain (e.g. ConversationalRetrievalChain). As of today, AmazonAPIGateway can be used only as LLM for text generation, but you cannot use it as embeddings for text embeddings generation (e.g. as part of ConversationalRetrievalChain)

### Motivation

Amazon API Gateway can be adopted for both Text generation and Text Embeddings. Amazon Bedrock provides different type of models (LLMs and Embeddings models). In this way, developers can use Amazon API Gateway for Retrieval Augmented Generation solutions

### Your contribution

The class can be defined as following:

```
from langchain.embeddings.bedrock import Embeddings
import requests
from typing import List

class AmazonAPIGatewayEmbeddings(Embeddings):
    def __init__(self, api_url, headers):
        self.api_url = api_url
        self.headers = headers

    def embed_documents(self, texts: List[str]) -> List[List[float]]:
        results = []
        for text in texts:
            response = requests.post(
                self.api_url,
                json={"inputs": text},
                headers=self.headers
            )
            results.append(response.json()[0]["embedding"])

        return results

    def embed_query(self, text: str) -> List[float]:
        response = requests.post(
                self.api_url,
                json={"inputs": text},
                headers=self.headers
            )

        return response.json()[0]["embedding"]


---

embeddings = AmazonAPIGatewayEmbeddings(
    api_url=f"{api_url}/invoke_model?model_id={model_id}",
    headers={
       ... # Required headers for the API invocation
    }
)

embeddings.embed_query("Hello, how are you?")
```
Arcee.ai LLM & Retriever integration
Labels: name: auto:enhancement, name: area: models

  - **Description:** This PR introduces a new LLM and Retriever API to https://arcee.ai for the python client
  - **Issue:** implements the integrations as requested in #11578 ,
  - **Dependencies:** no dependencies are required,
  - **Tag maintainer:** @hwchase17
  - **Twitter handle:** shwooobham 


**✅ `make format`, `make lint` and `make test` runs locally.**
```shell
=========== 1245 passed, 277 skipped, 20 warnings in 16.26s ===========
./scripts/check_pydantic.sh .
./scripts/check_imports.sh
poetry run ruff .
[ "." = "" ] || poetry run black . --check
All done! ✨ 🍰 ✨
1818 files would be left unchanged.
[ "." = "" ] || poetry run mypy .
Success: no issues found in 1815 source files
[ "." = "" ] || poetry run black .
All done! ✨ 🍰 ✨
1818 files left unchanged.
[ "." = "" ] || poetry run ruff --select I --fix .
poetry run codespell --toml pyproject.toml
poetry run codespell --toml pyproject.toml -w
```


**Contributions**
1. Arcee (langchain/llms), ArceeRetriever (langchain/retrievers), ArceeWrapper (langchain/utilities)
2. docs for Arcee (llms/arcee.py) and ArceeRetriever(retrievers/arcee.py)
3.

cc: @jacobsolawetz @ben-epstein
Support of Arcee.ai LLM and Retrievers
Labels: name: auto:enhancement, name: area: models

### Feature request
I propose to add the Python client for Arcee.ai as an LLM and retriever.

`arcee.py` under [langchain/utilities](https://github.com/langchain-ai/langchain/tree/master/libs/langchain/langchain/utilities)
`arcee.py` under [langchain/llms](https://github.com/langchain-ai/langchain/tree/master/libs/langchain/langchain/llms)
`arcee.py` under [langchain/retrievers](https://github.com/langchain-ai/langchain/tree/master/libs/langchain/langchain/retrievers)

```python
class Arcee(LLM):
     # client for Arcee's Domain Adapted Language Models (DALMs)
     # 
```

```python
class ArceeRetriever(BaseRetriever):
    # retriever for Arcee's DALMs
    # 
```

See: Client docs
https://github.com/arcee-ai/arcee-python

### Motivation

Arcee.ai offers seamless Domain Adaptation with its Specialized Domain Adapted Language Model system.
I want to utilize these adapted language models on https://arcee.ai and build applications with LangChain.

### Your contribution

Discussions - https://github.com/arcee-ai/arcee-python/issues/15
PR - https://github.com/langchain-ai/langchain/pull/11579
Sl integration
Labels: name: area: doc loader, name: auto:enhancement

<!-- 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/langchain-ai/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. It lives in `docs/extras` directory.

If no one reviews your PR within a few days, please @-mention one of @baskaryan, @eyurtsev, @hwchase17.
 -->
Add option to specify metadata columns in CSV loader
Labels: name: lgtm, name: area: doc loader, name: auto:improvement

#### Description
This PR adds the option to specify additional metadata columns in the CSVLoader beyond just `Source`. 

The current CSV loader includes all columns in `page_content` and if we want to have columns specified for `page_content` and `metadata` we have to do something like the below.:
```
csv = pd.read_csv(
        "path_to_csv"
    ).to_dict("records")

documents = [
        Document(
            page_content=doc["content"],
            metadata={
                "last_modified_by": doc["last_modified_by"],
                "point_of_contact": doc["point_of_contact"],
            }
        ) for doc in csv
    ]
```
#### Usage
Example Usage:
```
csv_test  =  CSVLoader(
      file_path="path_to_csv", 
      metadata_columns=["last_modified_by", "point_of_contact"]
 )
```
Example CSV:
```
content, last_modified_by, point_of_contact
"hello world", "Person A", "Person B"
```

Example Result:
```
Document {
 page_content: "hello world"
 metadata: {
 row: '0',
 source: 'path_to_csv',
 last_modified_by: 'Person A',
 point_of_contact: 'Person B',
 }
```
DOC: Wolfram Agent Link broken on README
Labels: name: area: doc loader, name: auto:documentation

### Issue with current documentation:

End-to-end Example: [GPT+WolframAlpha](https://huggingface.co/spaces/JavaFXpert/Chat-GPT-LangChain)

This link leads to a 404. A quick google search does not find a working page.

### Idea or request for content:

_No response_
Add Azure Redis example
Labels: name: auto:documentation, name: integration: redis

**Description**
This PR adds an additional Example to the Redis integration documentation. [The example](https://learn.microsoft.com/azure/azure-cache-for-redis/cache-tutorial-vector-similarity) is a step-by-step walkthrough of using Azure Cache for Redis and Azure OpenAI for vector similarity search, using LangChain extensively throughout. 

**Issue**
Nothing specific, just adding an additional example.

**Dependencies**
None.

**Tag Maintainer**
Tagging @hwchase17 :)