delayedkarma/langchain-issues huggingface dataset:
DOC: Under Modules/LLM/Integrations, the Sagemaker Endpoint integration example the "ContentHandler()" is giving an error

### Issue with current documentation:

The Example provided in the Documentation for the Integration of the Sagemaker Endpoint is giving the error 

```
An error occurred (ModelError) when calling the InvokeEndpoint operation: Received client error (400) from primary with message "{
  "code": 400,
  "type": "InternalServerException",
  "message": "Input payload must contain text_inputs key."
}
" 
```
The error comes from this block of code in the example:

`class ContentHandler(LLMContentHandler):
    content_type = "application/json"
    accepts = "application/json"

    def transform_input(self, prompt: str, model_kwargs: Dict) -> bytes:
        input_str = json.dumps({prompt: prompt, **model_kwargs})
        return input_str.encode('utf-8')
    
    def transform_output(self, output: bytes) -> str:
        response_json = json.loads(output.read().decode("utf-8"))
        return response_json[0]["generated_text"]`

specifically, because it does not contain the "text_inputs" key in the "transform_input" function of the "ContentHandler" class. 

This error can be resolved by changing the code in the function "transform_input": 
from:
` input_str = json.dumps({prompt: prompt, **model_kwargs})`
to:
`input_str = json.dumps({"text_inputs": prompt, **model_kwargs})`

But still, another error comes:

```
"in transform_output
    return response_json[0]["generated_text"]
KeyError: 0"
```
It is because of the function "transform_output" in the class "ContentHandler" class. 

This error can be resolved by changing the code in the function "transform_output": 
from: 
`return response_json[0]["generated_text"]` 
to:
`return response_json['generated_texts'][0]`

This makes the example code run properly without any errors. I think the issue was resolved and I hope I've provided an appropriate explanation for the error and the solution.

### Idea or request for content:

The Example of the Integration of the LLMs with the Sagemaker Endpoint that is present in the current documentation does not provide a working example because of the problem in the "ContentHandler" class, which generates errors :

1. `An error occurred (ModelError) when calling the InvokeEndpoint operation: Received client error (400) from primary with message "{
  "code": 400,
  "type": "InternalServerException",
  "message": "Input payload must contain text_inputs key."
}
" `

2. `"in transform_output
    return response_json[0]["generated_text"]
KeyError: 0"`

These errors pose a problem that can be solved with the code and recommendations provided above. Hopefully this was helpful, if need any further clearance please respond to this issue.
- Fix the parameter passing at as_retriever

```
qa = ConversationalRetrievalChain.from_llm(
    ChatOpenAI(
        openai_api_key=config.settings.BaseConfig.OPENAI_API_KEY,
        temperature=0.7,
        max_tokens=1024,
    ),
    documents_vector_store.as_retriever(
        filter={"user_id": user_id, "doc_id": doc_id}
    ),
    verbose=True,
    max_tokens_limit=1024,
)
```
- can't pass arguments (filter={"user_id": user_id, "doc_id": doc_id}) from documents_vector_store.as_retriever to the function self._collection.query
https://github.com/lyntcelec/langchain/blob/db45970a66f39a32f2cdd83e7bde26a404efad7b/langchain/vectorstores/chroma.py#LL121C21-L121C21
- It is not passed because the assignment is not reasonable
## 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

 -->
docs: Fixed the missing import in the chat/integrations example.

# Fixed the missing import in the chat/integrations example.

<!--
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!
-->

`AIMessage` is used in these examples, but it is not imported in the documentation.

ref: 
* https://python.langchain.com/en/latest/modules/models/chat/integrations/azure_chat_openai.html
* https://python.langchain.com/en/latest/modules/models/chat/integrations/google_vertex_ai_palm.html


<!-- Remove if not applicable -->



## 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

 -->
  - @hwchase17
  - @agola11
FileCallbackHandler

# like [StdoutCallbackHandler](https://github.com/hwchase17/langchain/blob/master/langchain/callbacks/stdout.py), but writes to a file

When running experiments I have found myself wanting to log the outputs of my chains in a more lightweight way than using WandB tracing. This PR contributes a callback handler that writes to file what `StdoutCallbackHandler` would print.

<!--
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!
-->

## Example Notebook

<!-- 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
-->

See the included `filecallbackhandler.ipynb` notebook for usage. Would it be better to include this notebook under `modules/callbacks` or under `integrations/`?
![image](https://github.com/hwchase17/langchain/assets/6439365/c624de0e-343f-4eab-a55b-8808a887489f)


## Who can review?

Community members can review the PR once tests pass. Tag maintainers/contributors who might be interested:

@agola11

<!-- 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

 -->
Adding support for async (_acall) for VertexAICommon LLM
Labels: name: lgtm

# Adding support for async (_acall) for VertexAICommon LLM

This PR implements the `_acall` method under `_VertexAICommon`. Because VertexAI itself does not provide an async interface, I implemented it via a ThreadPoolExecutor that can delegate execution of VertexAI calls to other threads.

Twitter handle: @polecitoem : )


## Who can review?

Community members can review the PR once tests pass. Tag maintainers/contributors who might be interested:

fyi - @agola11 for async functionality
fyi - @Ark-kun from VertexAI
fix chroma update_document to embed entire documents, fixes a characer-wise embedding bug

# Chroma update_document full document embeddings bugfix

Chroma update_document takes a single document, but treats the page_content sting of that document as a list when getting the new document embedding.

This is a two-fold problem, where the resulting embedding for the updated document is incorrect (it's only an embedding of the first character in the new page_content) and it calls the embedding function for every character in the new page_content string, using many tokens in the process.

<!--
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!
-->

<!-- Remove if not applicable -->

Fixes #5582

## 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

 -->

Tagging @dev2049 for vectorstore bugfix
Batched length functions for text splitters
Labels: name: auto:improvement

# Batched length functions for text splitters

Allows text splitters to take advantage of batched length functions instead of only calculating length on a single split at a time. This is particularly noticeable when using tokenized length functions, and even more so with huggingface "fast" tokenizers which have major performance improvements with batched input.

Additionally, by keeping track of the lengths of splits in the RecursiveCharacterTextSplitter and passing them into merge function it reduces the number of times that the same text needs to be re-tokenized.

Experimentally I've found that this speeds up text splitting around 5x when using a tokenized length function (of course depends heavily on the text being split, number of splits required, etc.)

@hwchase17
Chroma.update_document bug

### System Info

update_document only embeds a single document, but the single page_content string is cast to a list before embedding, resulting in a per-character embedding not a per-document embedding.
https://github.com/hwchase17/langchain/blob/4c572ffe959957b515528a9036b374f56cef027f/langchain/vectorstores/chroma.py#LL359C70-L359C70

### Who can help?

Related to @dev2049 vectorstores

### 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
- [X] Vector Stores / Retrievers
- [ ] Memory
- [ ] Agents / Agent Executors
- [ ] Tools / Toolkits
- [ ] Chains
- [ ] Callbacks/Tracing
- [ ] Async

### Reproduction

```
from langchain.docstore.document import Document
from langchain.vectorstores import Chroma
from tests.integration_tests.vectorstores.fake_embeddings import FakeEmbeddings

# Initial document content and id
initial_content = "foo"
document_id = "doc1"

# Create an instance of Document with initial content and metadata
original_doc = Document(page_content=initial_content, metadata={"page": "0"})

# Initialize a Chroma instance with the original document
docsearch = Chroma.from_documents(
    collection_name="test_collection",
    documents=[original_doc],
    embedding=FakeEmbeddings(),
    ids=[document_id],
)

# Define updated content for the document
updated_content = "updated foo"

# Create a new Document instance with the updated content and the same id
updated_doc = Document(page_content=updated_content, metadata={"page": "0"})

# Update the document in the Chroma instance
docsearch.update_document(document_id=document_id, document=updated_doc)

docsearch_peek = docsearch._collection.peek()
new_embedding = docsearch_peek['embeddings'][docsearch_peek['ids'].index(document_id)]
assert new_embedding \
    == docsearch._embedding_function.embed_documents([updated_content[0]])[0] \
    == docsearch._embedding_function.embed_documents(list(updated_content))[0] \
    == docsearch._embedding_function.embed_documents(['u'])[0]
assert new_embedding == docsearch._embedding_function.embed_documents([updated_content])[0]
```

### Expected behavior

The last assertion should be true
```
assert new_embedding == docsearch._embedding_function.embed_documents([updated_content])[0]
```
Add a "paged" mode for unstructured to include page number in metadata
Labels: name: lgtm

# Support "paged" mode for unstructured loader
<!--
UnstructuredPDF Loader now supports the mode "paged". This ensures content returned that are from the same page within the PDF are combined into a single Document object with metadata referencing back the page this content came from.

Twitter @RayzerCA
-->

## 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

  DataLoaders
  - @eyurtsev

 -->
ConversationSummaryBufferMemory (enhanced)

### Feature request

Currently, ConversationSummaryBufferMemory generates a summary of the conversation, then it passes this as part of the prompt to the MLL. The ConversationSummaryTokenBufferMemory will limit the size of the summary to X number of tokens, and it will remove data if necessary.

I believe adding one more parameter that overrides the max token limit and defaults it to 2000(current token limit) should be enough. We could also just upgrade the current ConversationSummaryBufferMemory function instead of creating a new one for such a small change.

### Motivation

I have not found a way to limit the size of the summary created by ConversationSummaryBufferMemory. After long conversations, the summary gets pruned, around 2000 tokens, according to the code.

A good use case will be to have control over the number of tokens being sent to the API. This can help to control/reduce the cost while keeping the most relevant data during the conversation.

I think this is a very simple change to do but can provide great control.

### Your contribution

I'm sorry, I don't feel confident enough to make a PR.

class ConversationSummaryTokenBufferMemory(BaseChatMemory, SummarizerMixin, MaxSummaryTokenLimit=2000):
    """Buffer with summarizer for storing conversation memory."""

    max_token_limit: MaxSummaryTokenLimit
    moving_summary_buffer: str = ""
    memory_key: str = "history"
[...]
Refactor and update databricks integration page
Labels: name: lgtm

# Your PR Title (What it does)

<!--
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!
-->

<!-- 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:

<!-- 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

 -->
Fix bedrock boto3 client instantiation
Labels: name: lgtm

https://github.com/hwchase17/langchain/pull/5523 has a small bug if client was not passed in constructor


## 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

 -->
Add missing comma in conv chat agent prompt json

# Add missing comma in conversational chat agent prompt json

Inspired by: https://github.com/hwchase17/langchainjs/pull/1498

<!--
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:
  Agents / Tools / Toolkits
  - @vowelparrot

<!-- 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

 -->
propagate callbacks to ConversationalRetrievalChain

# Allow callbacks to monitor ConversationalRetrievalChain

<!--
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!
-->

I ran into an issue where load_qa_chain was not passing the callbacks down to the child LLM chains, and so made sure that callbacks are propagated. There are probably more improvements to do here but this seemed like a good place to stop. 

Note that I saw a lot of references to callbacks_manager, which seems to be deprecated. I left that code alone for now.



## 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:
@agola11
<!-- 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

 -->
Fix typo in docugami.ipynb



# Fix typo in docugami.ipynb

<!--
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!
-->

<!-- Remove if not applicable -->

Fixed typo.
infromation -> information