delayedkarma/langchain-issues huggingface dataset:
Issue: previous message condensing time on `ConversationalRetrievalChain`

### Issue you'd like to raise.

I got a scenario where I'm using the `ConversationalRetrievalChain` with chat history. The problem is, it was streaming the condensed output of the question. Not the actual answer. So I separated the models, one for condensing the question and one for answering with streaming. But as I suspected, the condensing chain is eating up a time to generate the condensed output of the question, and the actual streaming of the answer is waiting for the condensed question generator. 

some of my implementations:

```python
callback = AsyncIteratorCallbackHandler()

q_generator_llm = ChatOpenAI(
    openai_api_key=settings.openai_api_key,
)

streaming_llm = ChatOpenAI(
    openai_api_key=settings.openai_api_key,
    streaming=True,
    callbacks=[callback],
)

question_generator = LLMChain(llm=q_generator_llm, prompt=CONDENSE_QUESTION_PROMPT)
doc_chain = load_qa_chain(llm=streaming_llm, chain_type="stuff", prompt=prompt)

qa_chain = ConversationalRetrievalChain(
    retriever=collection_store.as_retriever(search_kwargs={"k": 3}),
    combine_docs_chain=doc_chain,
    question_generator=question_generator,
    return_source_documents=True,
)

history = []

task = asyncio.create_task(
    qa_chain.acall({
        "question": q,
        "chat_history": history
    }),
)
```
___

### **Any workaround on how I avoid condensing the question to save time? Or any efficient way to resolve the issue?**

### Suggestion:

_No response_
Cypher search: Check if generated Cypher is provided in backticks
Labels: name: lgtm

# Check if generated Cypher code is wrapped in backticks

Some LLMs like the VertexAI like to explain how they generated the Cypher statement and wrap the actual code in three backticks:

![Screenshot from 2023-06-01 08-08-23](https://github.com/hwchase17/langchain/assets/19948365/1d8eecb3-d26c-4882-8f5b-6a9bc7e93690)


I have observed a similar pattern with OpenAI chat models in a conversational settings, where multiple user and assistant message are provided to the LLM to generate Cypher statements, where then the LLM wants to maybe apologize for previous steps or explain its thoughts. Interestingly, both OpenAI and VertexAI wrap the code in three backticks if they are doing any explaining or apologizing. Checking if the generated cypher is wrapped in backticks seems like a low-hanging fruit to expand the cypher search to other LLMs and conversational settings.
Allow users to pass local embeddings to Weaviate Hybrid Search Retriever

### Feature request

Fork off from this issue: https://github.com/hwchase17/langchain/issues/5300

The idea is to provide the WeaviateHybridSearchRetriever with the ability to use local embeddings similar to the Weaviate vectorstore. Specifically, for the `WeaviateHybridSearchRetriever.add_documents()` and `WeaviateHybridSearchRetriever.get_relevant_documents()` functions to work similar to the `Weviate.from_texts()` function where there is the option to use local embeddings if passed during creation. Additionally, the `WeaviateHybridSearchRetriever._create_schema_if_missing()` function likely needs to remove the default addition of a vectorizer in the schema object (related issue here: https://github.com/hwchase17/langchain/issues/5300).

### Motivation

This will allow those of us running Weaviate without embedding modules (like myself) to use the Weaviate Hybrid Search Retriever.

### Your contribution

I am planning on working to get a fix locally, I can potentially submit this as a PR down the line. Busy this week so others would probably beat me to it. I can review though.
OpenAI and Azure OpenAI - calls one after another

### System Info

langchain - 0.0.174 / 0.0.178 / 0.0.187
python3

### Who can help?

@hwchase17 @agola11 

### Information

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

### Related Components

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

### Reproduction

1. Call OpenAI setting the parameters -  openai_api_type , openai_api_version , openai_api_base , openai_api_key
-- Successful OpenAI request response
2. Call Azure OpenAI setting the parameters -  openai_api_type , openai_api_version , openai_api_base , openai_api_key
-- Fails
All subsequent calls fails

Alternatively, if you first call Azure OpenAI with parameters set correctly - that succeeds, but OpenAI fails. And all subsequent fails.

Each independently works - so guessing the. parameter values work as expected.  But when one after other is called, the second API (OpenAI or Azure OpenAI - which ever is called second) - fails




### Expected behavior

If parameters are set correctly, both should work as required.  If independently they work if app is restarted, why would it fail if they are called sequentiially?
Add Tigris vectorstore for vector search
Labels: name: enhancement, name: area: vector store

### Feature request

Support Tigris as a vector search backend

### Motivation

Tigris is a Serverless NoSQL Database and Search Platform and have their [vector search](https://www.tigrisdata.com/docs/concepts/vector-search/python/) product. It will be great option for users to use an integrated database and search product.

### Your contribution

I can submit a a PR
Issue:  how stream results with long context

### Issue you'd like to raise.

i follow the chapter  “Chat Over Documents with Chat History” to build a bot chat with pdf，
i want to streanming return,
but when i use stuff chain like this
```python
    doc_chain = load_qa_chain(OpenAI(temperature=0), chain_type="stuff", prompt=QA_PROMPT)
    chain = ConversationalRetrievalChain(
        retriever=vector_db.as_retriever(),
        question_generator=question_generator,
        combine_docs_chain=doc_chain
    )
```

it return "This model's maximum context length is 4097 tokens, however you requested 5741 tokens (5485 in your prompt; 256 for the completion). Please reduce your prompt; or completion length"

when i use map_reduce chain

```python
doc_chain = load_qa_chain(OpenAI(temperature=0,streaming=True,callbacks=[StreamingStdOutCallbackHandler()]), chain_type="map_reduce", combine_prompt=getQaMap_reducePromot())
```
it  return "Cannot stream results with multiple prompts."

how to resolve it when the context is too long


### Suggestion:

_No response_
Sampling parameters are ignored by vertexai

start_chat() constructs a vertextai _ChatSession and sets class variables with the parameters, but send_message() will not use those parameters if send_message is called w/o parameters.  This is because send_message() has default values for the parameters which are set to global variables.
You can fix this by moving **self._default_params to the send_message() call.

https://github.com/hwchase17/langchain/blob/359fb8fa3ae0b0904dbb36f998cd2339ea0aec0f/langchain/chat_models/vertexai.py#LL122C75-L122C75
Remove Chat Models 

### Feature request

Chat models relying on `SystemMessage`, ... instead of simple text, hinder creating longer prompts.
It would have been much simpler to avoid special casing chat models, and instead parse special tokens in the text prompt to separate system, human, ai, ...


### Motivation

Something similar to [this](https://github.com/microsoft/MM-REACT/blob/main/langchain/llms/openai.py#L211) that uses `
system\nsystem message
` would make it easier to keep the same code for models, and just use different prompts for chat endpints.

For example, it is perfectly valid to have 2 system messages, and I found it improves the results to have a system message at the beginning, and [one after](https://github.com/microsoft/MM-REACT/blob/main/langchain/agents/assistant/prompt.py#L191) some zero-shot examples right before the input.

### Your contribution

I can send the PR if there is any interest.
docs: unstructured no longer requires installing detectron2 from source

# Update Unstructured docs to remove the `detectron2` install instructions

Removes `detectron2` installation instructions from the Unstructured docs because installing `detectron2` is no longer required for `unstructured>=0.7.0`. The `detectron2` model now runs using the ONNX runtime.

## Who can review?

@hwchase17 
@eyurtsev
Skips creating boto client for Bedrock if passed in constructor

# Skips creating boto client if passed in constructor
Current LLM and Embeddings class always creates a new boto client, even if one is passed in a constructor. This blocks certain users from passing in externally created boto clients, for example in SSO authentication. 

## Who can review?
@hwchase17 
@jasondotparse 
@rsgrewal-aws

<!-- 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

 -->
Tracing V2 doesn't work

### System Info

```
$ langchain env
LangChain Environment:
library_version:0.0.184
platform:Linux-5.4.0-146-generic-x86_64-with-glibc2.31
runtime:python
runtime_version:3.11.3
```

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

### Reproduction

Following the [tracing v2 instructions](https://python.langchain.com/en/latest/tracing/agent_with_tracing.html#beta-tracing-v2), run:
```
$ langchain plus start
WARN[0000] The "OPENAI_API_KEY" variable is not set. Defaulting to a blank string. 
[+] Running 2/2
 ⠿ langchain-frontend Pulled                                                                                                 5.3s
 ⠿ langchain-backend Pulled                                                                                                  9.5s
unable to prepare context: path "frontend-react/." not found
langchain plus server is running at http://localhost.  To connect locally, set the following environment variable when running your LangChain application.
        LANGCHAIN_TRACING_V2=true
```

It looks like neither the `frontend-react` or `backend` folders referenced by the [`docker-compose.yaml`](https://github.com/hwchase17/langchain/blob/f72bb966f894f99c9ffc2c730be392c71d020ac8/langchain/cli/docker-compose.yaml#L14) are in the repository, thus docker won't build them.  Maybe we should remove the `build:` section of the YAML when deploying to users so they simply pull the images from the Docker Hub.

### Expected behavior

It should start properly.
Chroma: Constructor takes wrong embedding function (document vs query)

### System Info

Most recent version of Langchain
Python: 3.10.8
MacOS 13.4 - M1

### Who can help?

@hwchase17 
@agola11 

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

The Chroma constructor in the vectorstore section uses the document function when it should be the query function for embeddings. As a result, if the documents parameter is blank when using Chroma, Langchain will error out with a ValidationError. Please change line 95 to be embed_query instead of embed_documents [here](https://github.com/hwchase17/langchain/blob/master/langchain/vectorstores/chroma.py) in order for this to work / be consistent with the rest of the vectorstore wrappers

### Expected behavior

Use the query function instead of the documents function for use with embeddings in Chroma
Change methodology for scraping
Labels: name: area: doc loader, name: auto:improvement

It seems that the ReadTheDocsLoader is trying to parse and clean HTML contents from specific tags in the HTML file. If the HTML file doesn't contain the exact tag, the page_content will be empty.

The loader is looking for the "main" tag with the id "main-content" and if it doesn't find it, it's looking for a "div" tag with the role "main". If neither is found, it returns an empty string.

One way to fix this issue is to adjust the tags to those present in the HTML files to be scraped.

@eyurtsev
Fix: Qdrant ids
Labels: name: lgtm

# Fix Qdrant ids creation

There has been a bug in how the ids were created in the Qdrant vector store. They were previously calculated based on the texts. However, there are some scenarios in which two documents may have the same piece of text but different metadata, and that's a valid case. Deduplication should be done outside of insertion.

It has been fixed and covered with the integration tests.

## Who can review?

@dev2049 @hwchase17
Reference OpenAIEmbeddings client attr as private
Labels: name: area: embeddings, name: auto:bug

Reference OpenAIEmbeddings client attr as private

When utilising Pylance it is currently unable to manage interpretation of the `client` attribute within `OpenAIEmbeddings` as private. This results in the following errors being displayed:

![Screenshot 2023-05-31 at 17 19 34](https://github.com/hwchase17/langchain/assets/38786/bb19e39a-2abd-471b-afd0-b3568913bd44)

Additionally newer versions of `mypy` also identify this issue:

`tests/integration_tests/embeddings/test_openai.py:11: error: Missing named argument "client" for "OpenAIEmbeddings"  [call-arg]`

One minor note is that I've include a property setter to preserve any access patterns for `OpenAIEmbeddings.client`

/cc @hwchase17 - project lead
/cc @agola11 - Models
add allow_download as class attribute for GPT4All
Labels: name: lgtm

# Added support for download GPT4All model if does not exist

I've include the class attribute `allow_download` to the GPT4All class. By default, `allow_download` is set to False.

## Changes Made
- Added a new class attribute, `allow_download`, to the GPT4All class.
- Updated the `validate_environment` method to pass the `allow_download` parameter to the GPT4All model constructor.

## Context
This change provides more control over model downloading in the GPT4All class. Previously, if the model file was not found in the cache directory `~/.cache/gpt4all/`, the package returned error "Failed to retrieve model (type=value_error)". Now, if `allow_download` is set as True then it will use GPT4All package to download it . With the addition of the `allow_download` attribute, users can now choose whether the wrapper is allowed to download the model or not.

## Dependencies
There are no new dependencies introduced by this change. It only utilizes existing functionality provided by the GPT4All package.

## Testing
Since this is a minor change to the existing behavior, the existing test suite for the GPT4All package should cover this scenario

## Reviewers
 - @hwchase17
 - @agola11
Automatically detect input_variables from PromptTemplate string

### Feature request

If input_variables is not passed, try to detect them automatically as those which are surrounded by curly braces:

E.g. 
```
prompt_template = PromptTemplate(template="What is the price of {product_name}?")  ## Automatically detects the input_variables to be ['product_name']
```



### Motivation

This has been bugging me for a while and makes it more cumbersome.

### Your contribution

You can use the code mentioned below, it's literally that simple (at least for f-strings). 

I can submit a PR.


```
def str_format_args(x: str, named_only: bool = True) -> List[str]:
    ## Ref: https://stackoverflow.com/a/46161774/4900327
    args: List[str] = [
        str(tup[1]) for tup in string.Formatter().parse(x)
        if tup[1] is not None
    ]
    if named_only:
        args: List[str] = [
            arg for arg in args
            if not arg.isdigit() and len(arg) > 0
        ]
    return args


str_format_args("What is the price of {product_name}?")  ## Returns ['product_name']
```
ConversationalRetrievalChain new_question only from the question_generator only for retrieval and not for combine_docs_chain

### Discussed in https://github.com/hwchase17/langchain/discussions/5499

<div type='discussions-op-text'>

<sup>Originally posted by **lucasiscovici** May 31, 2023</sup>
Hello and thank you for this amazing library.

Here we : 
- get question
- get new_question with the question_generator
- retrieve docs with _get_docs and the new_question
- call the combine_docs_chain with the new_question and the docs

1/ It's possible to allow to call the question_generator event if the chat_history_str is empty ? 
i have to transform the question to search query to call the search engine even if the chat history is empty

2/ It's possible to not use the new_question in the combine_docs_chain call ?
i need the true question and not the new question (the search query) to call the llm for the qa

Thanks in advance

```python
    def _call(
        self,
        inputs: Dict[str, Any],
        run_manager: Optional[CallbackManagerForChainRun] = None,
    ) -> Dict[str, Any]:
        _run_manager = run_manager or CallbackManagerForChainRun.get_noop_manager()
        question = inputs["question"]
        get_chat_history = self.get_chat_history or _get_chat_history
        chat_history_str = get_chat_history(inputs["chat_history"])

        if chat_history_str:
            callbacks = _run_manager.get_child()
            new_question = self.question_generator.run(
                question=question, chat_history=chat_history_str, callbacks=callbacks
            )
        else:
            new_question = question
        docs = self._get_docs(new_question, inputs)
        new_inputs = inputs.copy()
        new_inputs["question"] = new_question
        new_inputs["chat_history"] = chat_history_str
        answer = self.combine_docs_chain.run(
            input_documents=docs, callbacks=_run_manager.get_child(), **new_inputs
        )
        if self.return_source_documents:
            return {self.output_key: answer, "source_documents": docs}
        else:
            return {self.output_key: answer}
```
Add Managed Motorhead
Labels: name: area: memory, name: lgtm

# Add Managed Motorhead
This change enabled MotorheadMemory to utilize Metal's managed version of Motorhead. We can easily enable this by passing in a `api_key` and `client_id` in order to hit the managed url and access the memory api on Metal.

Twitter: [@softboyjimbo](https://twitter.com/softboyjimbo)

## Who can review?

Community members can review the PR once tests pass. Tag maintainers/contributors who might be interested:

 @dev2049 @hwchase17
Add "name" parameter in Request body under messages for chat completions via OpenAI API
Labels: name: auto:improvement

Add "name" parameter in Request body under messages for chat completions via OpenAI API


This adds "name" parameter to the request body inside "messages".
For example, when defining HumanMessage or AIMessage, there is now option to add name parameter like this:
```py
 HumanMessage(content="Hello! what is my name?", name='Ilya')
```
As in OpenAI API: https://platform.openai.com/docs/api-reference/chat/create#chat/create-name
![image](https://github.com/hwchase17/langchain/assets/102866132/d7d32bd7-11b7-4449-bfda-ddbf0805cd1b)


The message dictionaries look like this (of course name parameter is optional):
```py
{'role': 'system', 'content': "That's goofy conversation without rules"}
{'role': 'user', 'name': 'Spy', 'content': 'Hello! what is my name? And your name?'}
{'role': 'assistant', 'name': 'Scout', 'content': "Hi! I won't answer your question, You mad? :P "}
{'role': 'assistant', 'name': 'Heavy', 'content': "Bruh man, don't be mean"}
{'role': 'user', 'name': 'spy', 'content': 'As you wish, Scout. Off to visit your mom ヾ(•ω•`)o'}
{'role': 'system', 'content': "summarize the conversation and list it's participants"}
```

## Simple test
```py
import os
from dotenv import load_dotenv
load_dotenv()
from langchain.llms import OpenAI
from langchain.chat_models import ChatOpenAI
from langchain import PromptTemplate, LLMChain
from langchain.prompts.chat import (
    ChatPromptTemplate,
    SystemMessagePromptTemplate,
    AIMessagePromptTemplate,
    HumanMessagePromptTemplate,
)
from langchain.schema import (
    AIMessage,
    HumanMessage,
    SystemMessage
)

chat = ChatOpenAI(model_name="gpt-4",temperature=1) # change gpt-4 to gpt-3.5-turbo if you doesn't have gpt-4 access yet
messages = [
    SystemMessage(content="That's goofy conversation without rules"),
    HumanMessage(content="Hello! what is my name? And your name?", name='Spy'),
    AIMessage(content="Hi! I won't answer your question, You mad? :P ", name='Scout'),
    AIMessage(content="Bruh man, don't be mean", name='Heavy'),
    HumanMessage(content="As you wish, Scout. Off to visit your mom ヾ(•ω•`)o", name='spy'),
    SystemMessage(content="summarize the conversation and list it's participants")

]
response=chat(messages)

print(response.content,end='\n')
```
Response should be smt like this:
```
Participants: User (Spy), Assistant (Scout), Assistant (Heavy)

Summary: The User initiates a goofy conversation asking about names. Assistant (Scout) responds playfully by not answering the question, then Assistant (Heavy) advises to not be mean. The User then continues with a witty remark about visiting Assistant (Scout)'s mom.
```

## Maintainers/contributors who might be interested:

  Models
  @hwchase17
  @agola11

  VectorStores / Retrievers / Memory
  @dev2049
Text splitter regex

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