delayedkarma/langchain-issues huggingface dataset:
Help: How to stop the chain if no chunks are retrieved?
Labels: name: auto:question, name: area: models

### Issue you'd like to raise.

I am using ConversationalRetrievalChain for RAG based chatbot and I am using custom retriever to get the relevant chunks.


```
custom_retriever = FilteredRetriever(
        vectorstore=vectorstore.as_retriever(search_kwargs={"k": 5, "filter": {}}, search_type="mmr"),
        category=sess_metadata["category"],
        product=sess_metadata["product"],
        service=sess_metadata["service"],
    )

qa_chain = ConversationalRetrievalChain.from_llm(
        llm=llm,
        retriever=custom_retriever,
        chain_type="stuff",
        combine_docs_chain_kwargs=QA_PROMPT,
        return_source_documents=True,
        verbose=True,
    )
    result = qa_chain({"question": translated_query, "chat_history": chat_history})
```

If no chunks are retrieved then I don't want the LLM to execute and just return a simple response to the customer. 
How can I do that?

### Suggestion:

_No response_
DOC: Where i can find Elasticsearch integration docs?
Labels: name: area: doc loader, name: area: vector store, name: auto:documentation

### Issue with current documentation:

`/usr/local/lib/python3.9/dist-packages/langchain/vectorstores/elastic_vector_search.py:135: UserWarning: ElasticVectorSearch will be removed in a future release. See Elasticsearch integration docs on how to upgrade.`

### Idea or request for content:

_No response_
Corrected Typo in MultiPromptChain Example in router.ipynb
Labels: name: auto:documentation

Refined the example in router.ipynb by addressing a minor typographical error. The typo "rins" has been corrected to "rains" in the code snippet that demonstrates the usage of the MultiPromptChain. This change ensures accuracy and consistency in the provided code example.

This improvement enhances the readability and correctness of the notebook, making it easier for users to understand and follow the demonstration. The commit aims to maintain the quality and accuracy of the content within the repository.

Thank you for your attention to detail, and please review the change at your convenience.

@baskaryan , @hwchase17
Fixed Grammatical errors in tutorials.mdx
Labels: name: auto:documentation

I want to convey my deep appreciation to the creator for their expert craftsmanship in developing this exceptional application. 👏 The remarkable dedication to upholding impeccable grammar and spelling in the documentation significantly enhances the polished and seamless experience for readers.

I want to stress that your feedback is invaluable to us and is genuinely cherished.

With gratitude,
@baskaryan, @hwchase17

<!-- Thank you for contributing to LangChain!

Replace this entire comment with:
  - Description: a description of the change, 
  - Issue: the issue # it fixes (if applicable),
  - Dependencies: any dependencies required for this change,
  - Tag maintainer: for a quicker response, tag the relevant maintainer (see below),
  - Twitter handle: we announce bigger features on Twitter. If your PR gets announced and you'd like a mention, we'll gladly shout you out!

Please make sure your PR is passing linting and testing before submitting. Run `make format`, `make lint` and `make test` to check this locally.

See contribution guidelines for more information on how to write/run tests, lint, etc: 
https://github.com/hwchase17/langchain/blob/master/.github/CONTRIBUTING.md

If you're adding a new integration, please include:
  1. a test for the integration, preferably unit tests that do not rely on network access,
  2. an example notebook showing its use. These live is docs/extras directory.

If no one reviews your PR within a few days, please @-mention one of @baskaryan, @eyurtsev, @hwchase17, @rlancemartin.
 -->
Corrected Grammatical errors in tutorials.mdx
Labels: name: auto:documentation

I want to extend my heartfelt gratitude to the creator for masterfully crafting this remarkable application. 🙌 I am truly impressed by the meticulous attention to grammar and spelling in the documentation, which undoubtedly contributes to a polished and seamless reader experience.

As always, your feedback holds immense value and is greatly appreciated.

@baskaryan , @hwchase17
why the  vector database  of vectorstores  must   load  document ？
Labels: name: area: embeddings, name: area: doc loader, name: area: vector store, name: auto:question, name: auto:documentation

### Issue with current documentation:

code 
-------------
raw_documents = TextLoader('../../../state_of_the_union.txt').load()
text_splitter = CharacterTextSplitter(chunk_size=1000, chunk_overlap=0)
documents = text_splitter.split_documents(raw_documents)
db = Chroma.from_documents(documents, OpenAIEmbeddings())

query = "What did the president say about Ketanji Brown Jackson"
docs = await db.asimilarity_search(query)

--------------
"chroma" requires the input of a document when used. If I have existing data in my vector library and only need to retrieve data without uploading new ones, I cannot define a vectorDB.
 
myflow

query   ----->   embedding  ----->  vectorDB ----> llm  ----->  out  

the  vectorDB  existing data, don't nedd  load  document

how abount use  vectorstores ? 







### Idea or request for content:

_No response_
Patch to pass attribute_filter to kendra query call with get_relevant_documents kendra retriever method
Labels: name: auto:improvement

**Description:** 

- Add attribute_filter as an optional input argument to get_relevant_documents method of kendra retriever class. Currently it is only possible to define an attribute_filter, used to filter kendra searched docs by metadata attributes (such as s3 prefix), when creating a Kendra retriever instance. 

- This patch to add attribute_filter as an optional argument to get_relevant_documents would enable programmatic changes in query filters to more easily support map reduce design patterns. 

- This change simply passes the optional attribute_filter dict as an optional argument to the _kendra_query method. 
- It does not store the attribute_filter as a class attribute as is the case for an attribute_filter defined when creating Kendra retriever class instance. 

- If a class attribute_filter instance exists, the attribute_filter provided during get_relevant_documents supersedes it.


**Tests:**

- This is a very minor, small change. Nonetheless I still ran `make docker_tests`.
- The only kendra relevant output was below and it does not pertain to the changes made:
- `langchain/retrievers/kendra.py:24
   /app/langchain/retrievers/kendra.py:24: DeprecationWarning: invalid escape sequence '\s'
     res = re.sub("\s+", " ", excerpt).replace("...", "")`
Update default index type and metric type for MyScale vector store
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/hwchase17/langchain/blob/master/.github/CONTRIBUTING.md

If you're adding a new integration, please include:
  1. a test for the integration, preferably unit tests that do not rely on network access,
  2. an example notebook showing its use. These live is docs/extras directory.

If no one reviews your PR within a few days, please @-mention one of @baskaryan, @eyurtsev, @hwchase17, @rlancemartin.
 -->

We update the default index type from `IVFFLAT` to `MSTG`, a new vector type developed by MyScale.
Error when trying to use ConversationBufferMemory with LLMChain
Labels: name: area: memory, name: auto:bug, name: area: models

### System Info

Python 3.10
LangChain v0.0.266

### Who can help?

@eyurtsev 
@hwchase17 

### Information

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

### Related Components

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

### Reproduction

Run the attached python test file

[test.py.zip](https://github.com/langchain-ai/langchain/files/12364594/test.py.zip)


Error observed:

[LCError.txt](https://github.com/langchain-ai/langchain/files/12364595/LCError.txt)


My python virtual environment is set with the following libraries:

openai==0.27.2
python-dotenv
tiktoken==0.3.1
langchain==0.0.266

### Expected behavior

Complete program without errors
CSV Agent Issue
Labels: name: area: agent, name: auto:bug, name: area: models

### System Info

This code is exactly as in the documentation.

```
import os 
from dotenv import load_dotenv
from langchain.agents import create_csv_agent
from langchain.llms import OpenAI

load_dotenv()


agent = create_csv_agent(OpenAI(temperature=0),
                         'train.csv',
                         verbose=True)
```


However, I receive this error. I have pydantic 2 installed as this is the latest version. I tried with pydantic v1 and it still doesnt work. 


  File "/Users/user/Desktop/coding/xero-python-oauth2-starter/venv/lib/python3.11/site-packages/langchain/agents/agent.py", line 13, in <module>
    from pydantic_v1 import BaseModel, root_validator
ModuleNotFoundError: No module named 'pydantic_v1'


I'm not sure if this is a me issue, but I've tried the common sense methods of checking. 


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

### Reproduction

Code is provided. 

### Expected behavior

I should be able to use the csv agent.
Use custom dictionary for retriever
Labels: name: area: embeddings, name: area: vector store, name: auto:question, name: auto:improvement

### Issue you'd like to raise.

Is it possible to use a customized dictionary for langchain retriever to search for document?
For example, there is document talking about "circuit". In my organization, people use special keyword "A" which means "circuit". However, this "A" == "circuit" is not a common relationship in embedding system. 
Is it possible to let langchain retriever knows this "A" == "circuit" relationship, so it can search the document talking about "circuit" without fine-tune the embedding model?

### Suggestion:

_No response_
:hourglass_flowing_sand:  docstrings: `vectorstores` consistency
Labels: name: area: vector store, name: auto:documentation

:hourglass_flowing_sand: 
- updated the top-level descriptions to a consistent format;
- changed several `ValueError` to `ImportError` in the import cases;
- changed the format of several internal functions from "name" to "_name". So, these functions are not shown in the Top-level API Reference page (with lists of classes/functions)

@baskaryan BTW Are we going to try [this OpenAI content moderation](https://openai.com/blog/using-gpt-4-for-content-moderation) for our docs?
Add exclude_output_keys to VectorStoreRetrieverMemory
Labels: name: area: memory, name: area: vector store, name: auto:improvement

### Feature request

Add the parameter exclude_output_keys to VectorStoreRetrieverMemory and exclude output keys in method _form_documents similar to the case of input keys. This would enable the use of VectorStoreRetrieverMemory as read-only memory.
https://github.com/langchain-ai/langchain/blob/2e8733cf54d3cd24cf6927e4d52a212ead88be8e/libs/langchain/langchain/memory/vectorstore.py

### Motivation

I am using the ConversationChain to create a ChatBot that impersonates fictional characters based on extensive information that does not fit in the limited context size available. Therefore, I want to store the character information and the chat history from multiple sessions in two Chroma databases. While the ConversationChain populates the chat history database, the character information should be read-only.
Using exclude_input_keys resulted in only the LLM outputs being saved in the character information database. Here, it would be beneficial to be able to exclude the output_key from being stored as well.

### Your contribution

```
    exclude_output_keys: Sequence[str] = Field(default_factory=tuple)
    """Output keys to exclude when constructing the document"""
```

```
def _form_documents(
    self, inputs: Dict[str, Any], outputs: Dict[str, str]
    ) -> List[Document]:
    """Format context from this conversation to buffer."""
    # Each document should only include the current turn, not the chat history
    excluded_inputs = set(self.exclude_input_keys)
    excluded_inputs.add(self.memory_key)
    filtered_inputs = {k: v for k, v in inputs.items() if k not in excluded_inputs}
    excluded_outputs = set(self.exclude_output_keys)
    filtered_outputs = {k: v for k, v in outputs.items() if k not in excluded_outputs}
    texts = [
        f"{k}: {v}"
        for k, v in list(filtered_inputs.items()) + list(filtered_outputs.items())
    ]
    page_content = "\n".join(texts)
    return [Document(page_content=page_content)]
```

I did not check if passing an empty string to Document will work or throw an error.
Type error in ParentDocumentRetriever using LocalFileStore
Labels: name: area: vector store, name: auto:bug

### Bug

 LocalFileStore tries to treat Document as byte
```
store = LocalFileStore(get_project_relative_path("doc_store"))
    parent_splitter = RecursiveCharacterTextSplitter(chunk_size=2000)
    child_splitter = RecursiveCharacterTextSplitter(chunk_size=400)
    retriever = ParentDocumentRetriever(vectorstore=vectorstore,
                                        docstore=store,
                                        parent_splitter=parent_splitter,
                                        child_splitter=child_splitter)
    if embed:
        docs = []
        data_folder = get_project_relative_path("documents")
        for i, file_path in enumerate(data_folder.iterdir()):
            document = TextLoader(str(file_path))
            docs.extend(document.load())
        retriever.add_documents(docs, None)
```
Here the broken method:
```
    def mset(self, key_value_pairs: Sequence[Tuple[str, bytes]]) -> None:
        """Set the values for the given keys.

        Args:
            key_value_pairs: A sequence of key-value pairs.

        Returns:
            None
        """
        for key, value in key_value_pairs:
            full_path = self._get_full_path(key)
            full_path.parent.mkdir(parents=True, exist_ok=True)
            full_path.write_bytes(value)
```

TypeError: memoryview: a bytes-like object is required, not 'Document'



### Who can help?

_No response_

### Information

- [X] The official example notebooks/scripts
- [ ] My own modified scripts

### Related Components

- [ ] LLMs/Chat Models
- [ ] Embedding Models
- [ ] Prompts / Prompt Templates / Prompt Selectors
- [ ] Output Parsers
- [ ] Document Loaders
- [X] Vector Stores / Retrievers
- [ ] Memory
- [ ] Agents / Agent Executors
- [ ] Tools / Toolkits
- [ ] Chains
- [ ] Callbacks/Tracing
- [ ] Async

### Reproduction

Create a LocalFileStore
Use a ParentDoucmentRetriever


### Expected behavior

Serialize the documents as bytes
Cache linting venv on CI.
Labels: name: auto:nit

Ensure that we cache the linting virtualenv as well as the pip cache for the `pip install -e langchain` step.

This is a win of about 60-90s overall.

Before:
![image](https://github.com/langchain-ai/langchain/assets/2348618/f55f8398-2c3a-4112-bad3-2c646d186183)

After:
![image](https://github.com/langchain-ai/langchain/assets/2348618/984a9529-2431-41b4-97e5-7f5dd7742651)
How to fix "Token indices sequence length is longer than the specified maximum sequence length for this model"?
Labels: name: area: doc loader, name: auto:question, name: area: models

### Issue you'd like to raise.

I'm running llama2-13b with the below parameters, and I'm trying to summarize pdf (linked [here](https://akoustis.com/wp-content/uploads/2022/06/Single-Crystal-AlScN-on-Silicon-XBAW%E2%84%A2RF-Filter-Technology-for-Wide-Bandwidth-High-Frequency-5G-and-Wi-Fi-Applications.pdf))

```
"properties": {
                    "max_new_tokens": 1500,
                    "temperature": 0.2,
                    "top_p": 0.95,
                    "repetition_penalty": 1.15
                }
```

I split the document bypages and run the load_summarize_chain. But I get an error:
```
Token indices sequence length is longer than the specified maximum sequence length for this model (13243 > 1024). Running this sequence through the model will result in indexing errors
Token indices sequence length is longer than the specified maximum sequence length for this model (1164 > 1024). Running this sequence through the model will result in indexing errors
ModelError: An error occurred (ModelError) when calling the InvokeEndpoint operation: Received server error (507) from primary and could not load the entire response body.
```

How do I split the pdf document or what chain/prompt should I use to summarize large pdfs and respect the max_new_tokens=1024 for llama2.

Code
```
from langchain.document_loaders import PyPDFLoader
loader = PyPDFLoader("Single-Crystal-AlScN-on-Silicon-XBAW™RF-Filter-Technology-for-Wide-Bandwidth-High-Frequency-5G-and-Wi-Fi-Applications.pdf")
pages = loader.load_and_split()
chain = load_summarize_chain(llm,chain_type="map_reduce")
x =chain.run(pages)
```

### Suggestion:

_No response_
[Fix] Update litellm to use model instead of model_name
Labels: name: lgtm, name: auto:nit, name: area: models

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

The previous caching configuration was attempting to cache poetry venvs created in the default shared virtualenvs directory. However, all langchain packages use `in-project = true` for their poetry virtualenv setup, which moves the venv inside the package itself instead. This meant that poetry venvs were not being cached at all.

This PR ensures that the venv gets cached by adding the in-project venv directory to the cached directories list.

It also makes sure that the cache key *only* includes the lockfile being installed, as opposed to *all lockfiles* (unnecessary cache misses) or just the *top-level lockfile* (cache hits when it shouldn't).
📖 docs: `integrations/agent_toolkits` 
Labels: name: auto:documentation

Note: There are no changes in the file names!

- The group name on the main navbar changed: `Agent toolkits` -> `Agents & Toolkits`. Examples here are the mix of the Agent and Toolkit examples because Agents and Toolkits in examples are always used together.
- Titles changed: removed "Agent" and "Toolkit" suffixes. The reason is the same.
- Formatting: mostly cleaning the header structure, so it could be better on the right-side navbar.

Main navbar is looking much cleaner now.
pydantic v2 bump -- test required changes
Labels: name: area: agent, name: auto:refactor

List of required changes after bumping langchain using bump-pydantic.

1. Decouple langsmith and langchain, copy over schema to langchain
2. Use new metaclass for pydantic v2 in tool base
3. WHEN ON PYDANTIC 2 

 tool base:
```
def _create_subset_model(
    name: str, model: BaseModel, field_names: list
):
    """Create a pydantic model with only a subset of model's fields."""
    fields = {}
    for field_name in field_names:
        field = model.__fields__[field_name]
        fields[field_name] = (field.annotation, field)
    return create_model(name, **fields)  # type: ignore
```

utils
```python
def get_pydantic_field_names(pydantic_cls: Any) -> Set[str]:
    """Get field names, including aliases, for a pydantic class.

    Args:
        pydantic_cls: Pydantic class."""
    all_required_field_names = set()
    for name, field in pydantic_cls.__fields__.items():
        all_required_field_names.add(name)
        if field.alias:
            all_required_field_names.add(field.alias)
    return all_required_field_names

```
6. Add missing type annotations to pydantic objects (as these raise exceptions)
7. model_validator -> root_validator(skip_on_failure=True)
8. find -type f -name "*.py" -exec sed -i "s/@root_validator()/@root_validator(skip_on_failure=True)/g" {}  +