delayedkarma/langchain-issues huggingface dataset:
`Docx2txtLoader` isn't loading docx files properly
Labels: name: area: doc loader, name: auto:bug

### System Info

Langchain version: 0.0.323
Platform: MacOS Sonoma
Python version: 3.11

### Who can help?

@eyurtsev

### 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
- [X] Document Loaders
- [ ] Vector Stores / Retrievers
- [ ] Memory
- [ ] Agents / Agent Executors
- [ ] Tools / Toolkits
- [ ] Chains
- [ ] Callbacks/Tracing
- [ ] Async

### Reproduction

`Docx2txtLoader` isn't handling improperly encoded docx files and is throwing errors.

Code:
```python
from langchain.document_loaders import Docx2txtLoader

def main():
    file = 'elon_doc.docx'
    loader = Docx2txtLoader(file)
    text = loader.load()
    print(text)


if __name__ == '__main__':
    main()
```


```
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/Users/sidharthmohanty/Desktop/oss/test-docs/docx.py", line 11, in <module>
    main()
  File "/Users/sidharthmohanty/Desktop/oss/test-docs/docx.py", line 6, in main
    text = loader.load()
           ^^^^^^^^^^^^^
  File "/Users/sidharthmohanty/Desktop/oss/test-docs/dev_env/lib/python3.11/site-packages/langchain/document_loaders/word_document.py", line 55, in load
    page_content=docx2txt.process(self.file_path),
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/sidharthmohanty/Desktop/oss/test-docs/dev_env/lib/python3.11/site-packages/docx2txt/docx2txt.py", line 76, in process
    zipf = zipfile.ZipFile(docx)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/python@3.11/3.11.5/Frameworks/Python.framework/Versions/3.11/lib/python3.11/zipfile.py", line 1302, in __init__
    self._RealGetContents()
  File "/opt/homebrew/Cellar/python@3.11/3.11.5/Frameworks/Python.framework/Versions/3.11/lib/python3.11/zipfile.py", line 1369, in _RealGetContents
    raise BadZipFile("File is not a zip file")
zipfile.BadZipFile: File is not a zip file
```

To reproduce the issue please use this file: https://uploadnow.io/f/Mr0tybt.

### Expected behavior

It should handle it gracefully and extract text if possible. If the file is completely corrupted, it should show an error for a corrupted file.
Intergration hippo
Labels: name: area: vector store, 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.
 -->
Improve handling of empty queries for timescale vector
Labels: name: lgtm, name: area: vector store, name: auto:improvement

**Description:** Improve handling of empty queries in timescale-vector. For timescale-vector it is more efficient to get a None embedding when the embedding has no semantic meaning. It allows timescale-vector to perform more optimizations. Thus, when the query is empty, use a None embedding.

 Also pass down constructor arguments to the timescale vector client.

<!-- 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 template for Profanity-free translation using guardrails
Labels: 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.
 -->
More comprehensive readthedocs document loader
Labels: name: area: doc loader, name: auto:improvement

  ## **Description:**
When building our own readthedocs.io scraper, we noticed a couple interesting things:

1. Text lines with a lot of nested <span> tags would give unclean text with a bunch of newlines. For example, for [Langchain's documentation](https://api.python.langchain.com/en/latest/document_loaders/langchain.document_loaders.readthedocs.ReadTheDocsLoader.html#langchain.document_loaders.readthedocs.ReadTheDocsLoader), a single line is represented in a complicated nested HTML structure, and the naive `soup.get_text()` call currently being made will create a newline for each nested HTML element. Therefore, the document loader would give a messy, newline-separated blob of text. This would be true in a lot of cases.

<img width="945" alt="Screenshot 2023-10-26 at 6 15 39 PM" src="https://github.com/langchain-ai/langchain/assets/44193474/eca85d1f-d2bf-4487-a18a-e1e732fadf19">
<img width="1031" alt="Screenshot 2023-10-26 at 6 16 00 PM" src="https://github.com/langchain-ai/langchain/assets/44193474/035938a0-9892-4f6a-83cd-0d7b409b00a3">

Additionally, content from iframes, code from scripts, css from styles, etc. will be gotten if it's a subclass of the selector (which happens more often than you'd think). For example, [this page](https://pydeck.gl/gallery/contour_layer.html#) will scrape 1.5 million characters of content that looks like this:

<img width="1372" alt="Screenshot 2023-10-26 at 6 32 55 PM" src="https://github.com/langchain-ai/langchain/assets/44193474/dbd89e39-9478-4a18-9e84-f0eb91954eac">

Therefore, I wrote a recursive _get_clean_text(soup) class function that 1. skips all irrelevant elements, and 2. only adds newlines when necessary.

2. Index pages (like [this one](https://api.python.langchain.com/en/latest/api_reference.html)) would be loaded, chunked, and eventually embedded. This is really bad not just because the user will be embedding irrelevant information - but because index pages are very likely to show up in retrieved content, making retrieval less effective (in our tests). Therefore, I added a bool parameter `exclude_index_pages` defaulted to False (which is the current behavior — although I'd petition to default this to True) that will skip all pages where links take up 50%+ of the page. Through manual testing, this seems to be the best threshold.



## Other Information:
  - **Issue:** n/a
  - **Dependencies:** n/a
  - **Tag maintainer:** n/a
  - **Twitter handle:** @andrewthezhou
[Feature Request]: Self-RAG support (NEW TECHNIQUE) 
Labels: name: area: vector store, name: auto:enhancement, name: area: models

### Feature request

Self-RAG is a new open-source technique (MIT license) that implements:
1. **Adaptive retrieval via retrieval tokens:** allows you to fine-tune LLMs to output `[Retrieval]` tokens mid-generation to indicate when to perform retrieval. It has been empirically shown to improve open-source models to match ChatGPT level of performance in RAG tasks.
2. **Critique tokens:**
    - w_rel (default 1.0): This variable controls the emphasis on relevance during beam search.
    - w_sup (default 1.0): This variable controls the emphasis on support from the document during beam search.
    - w_use (default 0.5): This variable controls the emphasis on overall quality during beam search.

Requirements:
- make it compatible with vLLM for inference such that any fine-tuned Self-RAG model can be deployed in a framework with PagedAttention implemented.
- able to query vector database

Website: https://selfrag.github.io/
Model: https://huggingface.co/selfrag/selfrag_llama2_7b
Code: https://github.com/AkariAsai/self-rag

![image](https://github.com/run-llama/llama_index/assets/27340033/9911d86d-e44e-49b1-95ef-87f3b9a9e0e6)
![image](https://github.com/run-llama/llama_index/assets/27340033/b262766c-2318-431c-9714-a0738ad66fc4)


### Motivation

The main motivation behind the proposal is to allow for more precise responses while using RAG to help reduce hallucinations.

### Your contribution

I am not available to help with a contribution.
VectorDBQA bug on Gigachat
Labels: name: area: embeddings, name: area: vector store, name: auto:bug, name: area: models, name: integration: chroma

### System Info

Running on colab:
langchain==0.0.324
gigachat==0.1.6
gpt4all==2.0.1
chromadb==0.4.15
Python 3.10.12

### Who can help?

_No response_

### Information

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

### Related Components

- [X] LLMs/Chat Models
- [X] 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

1. Add gigachat creds
2. Run notebook: https://colab.research.google.com/drive/1LcLYyWYpu8ZGSVKvF-WOFFsF36M75DAp?usp=sharing

### Expected behavior

Expected to give relevant answer like in original notebook: https://github.com/hwchase17/chroma-langchain/blob/master/persistent-qa.ipynb
Update broken redis tests
Labels: name: area: vector store, name: auto:bug, name: integration: redis

Update broken redis tests -- tiny PR :) 
  - **Description:** Fixes Redis tests on master (look like it was broken by https://github.com/langchain-ai/langchain/pull/11257)
  - **Issue:** None,
  - **Dependencies:** No
  - **Tag maintainer:** @baskaryan @Spartee 
  - **Twitter handle:** N/A
Issue: SelfQueryRetriever and contains('string')
Labels: name: auto:improvement, name: area: models

### Issue you'd like to raise.

I have been experimenting with SelfQueryRetriever. I am trying to use it to find a book based on a query. 
For example: 
"Find me a book that was written by Hayek". 

The LLM correctly creates the query:
"query='Hayek' filter=Comparison(comparator=<Comparator.EQ: 'eq'>, attribute='Autor', value='Hayek') limit=None"

But, the problem is that in my metadata, I have full names of authors, for example: 
"Autor": "Friedrich A. Hayek"

And because the comparator is `eq`, therefore equality, the retriever does not find my book. A solution would be:
1. Add `contains` operator to the SelfQueryRetriever and allows us to turn it on/off using some parameter. We could do this by ourselves if you gave us access to the prompt that is being used to generate the query. I already requested this in a [separate issue](https://github.com/langchain-ai/langchain/issues/11735). 
2. Allow using of lists (so I could split the full name into an array of names). However [LangChain documentation](https://python.langchain.com/docs/modules/data_connection/retrievers/self_query/) says that it is possible to use lists for attributes, the testing shows that it is not possible. When trying to use a list, you will get the following error: 
`ValueError: Expected metadata value to be a str, int, float or bool, got ["Friedrich", "A.", "Hayek"] which is a <class 'list'>`

### Suggestion:

Please allow one of the two solutions. Either using `contains` with SelfQueryRetriever or allow using lists.
Support azure search from 11.4.0 onwards
Labels: name: area: vector store, name: auto:improvement

  - **Description:** Support azure-search-documents from 11.4.0b10 onwards (chose b11 now since latest released version).  Also fix hardcoded `metadata` field in `semantic_hybrid` search type
  - **Issue:** See [b10 changelog with breaking changes](https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/search/azure-search-documents/CHANGELOG.md#1140b10-2023-10-10)
  - **Tag maintainer:** @baskaryan
filter query within vector_store.similarity_search() is not working as expected.
Labels: name: area: vector store, name: auto:bug

### System Info

azure-search-documents==11.4.0b8, langchain

### Who can help?

@hwchase17 
@agola11 
@dosu-bot

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

    fields in azure search index and their content is as below:

    
    Code:
    memory_vector_store: AzureSearch = AzureSearch(
        azure_search_endpoint=vector_store_address,
        azure_search_key=vector_store_password,
        index_name=memory_index_name,
        embedding_function=embeddings.embed_query
        )
 user_id = "dtiw"
session_id = "ZjBlNmM4M2UtOThkYS00YjgyLThhOTAtNTQ0YTU1MTA3NmVm"
relevant_docs = memory_vector_store.similarity_search(
        query=query,
        k=4, 
        search_type="similarity",
        filters = f"user_id eq '{user_id}' and session_id eq '{session_id}'"
    )
    if relevant_docs:
        prev_history = "\n".join([doc.page_content for doc in relevant_docs])
    else:
        logging.info(f"relevant docs not found")
        prev_history = ""

logging.info(f" the relevant docs are {relevant_docs}")
logging.info(f"the previous history is {prev_history}")

### Expected behavior

expected answer:
 [Document(page_content='User: who are you?\nAssistant: I am an AI assistant here to help you with any company-related questions you may have. How can I assist you today?', metadata={'id': 'ZHRpd2FyaUBoZW5kcmlja3Nvbi1pbnRsLmNvbWYwZTZjODNlLTk4ZGEtNGI4Mi04YTkwLTU0NGE1NTEwNzZlZjIwMjMxMDI2MTk0MzI4', 'session_id': 'ZjBlNmM4M2UtOThkYS00YjgyLThhOTAtNTQ0YTU1MTA3NmVm', 'user_id': 'dtiw', '@search.score': 0.78985536, '@search.reranker_score': None, '@search.highlights': None, '@search.captions': None}), 
 
 Document(page_content='User: Hi, whats up?\nAssistant: Please stick to the company-related questions. How can I assist you with any company-related queries?', metadata={'id': 'ZHRpd2FyaUBoZW5kcmlja3Nvbi1pbnRsLmNvbWYwZTZjODNlLTk4ZGEtNGI4Mi04YTkwLTU0NGE1NTEwNzZlZjIwMjMxMDI2MTk0MjU5', 'session_id': 'ZjBlNmM4M2UtOThkYS00YjgyLThhOTAtNTQ0YTU1MTA3NmVm', 'user_id': 'dtiw', '@search.score': 0.7848022, '@search.reranker_score': None, '@search.highlights': None, '@search.captions': None})]

'User: who are you?\nAssistant: I am an AI assistant here to help you with any company-related questions you may have. How can I assist you today?'
'User: Hi, whats up?\nAssistant: Please stick to the company-related questions. How can I assist you with any company-related queries?'

Given answer:
the relevant docs are <iterator object azure.core.paging.ItemPaged at 0x7d82ae149b10>
the previous history is
langserve doc
Labels: 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.
 -->
E2B tool - Improve description wuth uploaded files info
Labels: name: lgtm, 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.
 -->
Improves the description of the installation command
Labels: name: lgtm, name: auto:documentation

- **Description:**

 Before: 
`
To install modules needed for the common LLM providers, run:
`

After:
`
To install modules needed for the common LLM providers, run the following command. Please bear in mind that this command is exclusively compatible with the `bash` shell:
`


> This is required for the user so that the user will know if this command is compatible with `zsh` or not.
Fix rrror "Could not parse function call data" for JsonKeyOutputFunctionsParser (and other Json parsers) without additional LLM call
Labels: name: auto:improvement, name: area: models

### Feature request

LangChain v0.0.323
Python 3.10.12
turbo-3.5 

I use JsonKeyOutputFunctionsParser to parse JSON output:

```
extraction_functions = [convert_pydantic_to_openai_function(Information)]
extraction_model = llm.bind(functions=extraction_functions, function_call={"name": "Information"})

prompt = ChatPromptTemplate.from_messages([
    ("system", "Extract the relevant information, if not explicitly provided do not guess. Extract partial info"),
    ("human", "{input}")
])

extraction_chain = prompt | extraction_model | JsonKeyOutputFunctionsParser(key_name="people")
```

For some text (in my tests it's 1 from 500) we have wrong JSON, because there are wrong placed comma or JSON is wrapped by extra text and that can't be parsed by json.loads.

It seems we can use OutputFixingParser, but in most of cases it's not needed to call LLM - we can just fix it my regex.

I did special code to fix such JSONs:

```
class JsonFixOutputFunctionsParser(JsonOutputFunctionsParser):
    """Parse an output as the Json object."""

    def get_fixed_json(self, text : str) -> str:
        """Fix LLM json"""
        text = re.sub(r'",\s*}', '"}', text)
        text = re.sub(r"},\s*]", "}]", text)
        text = re.sub(r"}\s*{", "},{", text)

        open_bracket = min(text.find('['), text.find('{'))
        if open_bracket == -1:
            return text

        close_bracket = max(text.rfind(']'), text.rfind('}'))
        if close_bracket == -1:
            return text
        return text[open_bracket:close_bracket+1]

    def parse_result(self, result: List[Generation], *, partial: bool = False) -> Any:
         .................
        fixed_json = self.get_fixed_json(str(function_call["arguments"]))
        return json.loads(fixed_json)

```

Now it works without error:

`extraction_chain_fixed = prompt | extraction_model | JsonFixOutputFunctionsParser()`

Code example with this bug and fix: https://colab.research.google.com/drive/1LiT6-ljO_g7xn4Y8qaXKZaUlcpVdEEGI?usp=sharing


### Motivation

With get_fixed_json we can avoid extra LLM call and easy and fast fix most of wrong Jsons.
I tested it on 9000 runs and it fixed all errors that I got.

### Your contribution

Feel free to use get_fixed_json function where we need to parse JSON, not only for function calls.
fix : replace openllm config params with user input rather than defau…
Labels: name: auto:bug, name: area: models

**Description:** Configured to update OpenLLM server configs with user specified values for each parameter. 
**Issue:** Currently user specified values for each parameter is overwritten by default values due to the mixed of order of python dictionary updates. 
**Dependencies:** No additional dependencies

@baskaryan , @eyurtsev , @hwchase17
Langchain evaluate_strings should allow custom output parsing
Labels: name: auto:improvement, name: area: models

### Feature request

Currently, there's only a specific output type for the evaluate_strings function in langchain.
{
   reasoning: "blah blah"
   score: 0 or 1
   value: "Y" or "N"
}

Ideally users should be able to override this with the type of request they would want. 


### Motivation

It really ties you down when you have to go with the same type of output parser. 

### Your contribution

I can work on a PR for the change.