delayedkarma/langchain-issues huggingface dataset:
Docs: improve similarity search examples
Labels: name: lgtm, name: area: doc loader, name: auto:documentation

**Description:** 

Examples in the "Select by similarity" section were not really highlighting capabilities of similarity search.
E.g. "# Input is a measurement, so should select the tall/short example" was still outputting the "mood" example.

I tweaked the inputs a bit and fixed the examples (checking that those are indeed what the search outputs).
PGVector 'mmr' does not apply the filter at the time of retrieval
Labels: name: area: vector store, name: auto:bug

### System Info

langchain==0.0.291

### Who can help?

_No response_

### Information

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

### Related Components

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

### Reproduction

```
elements_for_filter = ['a10','b10']
 the_filter = {
     'type': {
         'in': elements_for_filter
     }
 }
 if rag_similarity_strategy == 'similarity_score_threshold':
     retriever = vectordb.as_retriever(search_type=rag_similarity_strategy, search_kwargs={
          "k": 4, 'score_threshold': 0.6,
          'filter': the_filter})
 elif rag_similarity_strategy == 'mmr':
     retriever = vectordb.as_retriever(search_type=rag_similarity_strategy, search_kwargs={
         'filter': the_filter, "k": 4, 'lambda_mult': 0.5,
         'fetch_k': 20,
         })
```

### Expected behavior

I expect the retrieve apply the filter when I use 'mmr' as it does when I used 'similarity_score_threshold' but it does not.
Small changes to runnable docs
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.
 -->
Fix documents for RetrievalQAWithSourcesChain
Labels: name: lgtm, name: auto:documentation

  - **Description:** Fix typo about `RetrievalQAWithSourceChain`  ->  `RetrievalQAWithSourcesChain`
<!-- 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.
 -->
VLLMOpenAI class should be generalised
Labels: name: auto:improvement, name: auto:refactor, name: area: models

### Feature request

we are using your VLLMOpenAI class in a project to connect to our vLLM. we however don't use openAI, and found kind of weird that you have this implemented, but naming suggests it is specifically for openAI only. You could generalise this class so that it can be used with any kind of vLLM (which it already does). So basically just some refactoring might be the whole thing.

### Motivation

We are using this VLLMOpenAI class with other open source models. Kind of misleading and unintuitive to say we use the VLLMOpenAI class. We wish ourselves a custom class for open source models or any other kind of vLLM deployment.

### Your contribution

No time capacity :( So other than my genuine enthusiasm on your project and the whole documenting of the feature I can't really offer much more...
[Feature Request] Chain-of-Verification (CoVe) 
Labels: name: auto:enhancement, name: area: models

### Feature request

Hi, I'd like to request the chain type of Chain-of-Verification (CoVe).

### Motivation

I see that there's already a `LLMCheckerChain` and a `SmartLLMChain` which use related techniques, but implementing the below four-step process as described in https://arxiv.org/abs/2309.11495 would, I think, still be a very popular feature.


**Chain-of-Verification steps:**
1. drafts an initial response
2. plans verification questions to fact-check its draft
3. answers those questions independently so the answers are not biased by other responses
4. generates its final verified response

### Your contribution

Not sure yet.
Remove extra spaces
Labels: name: lgtm, name: area: doc loader, name: auto:documentation

  ### Description
When I was reading the document, I found that some examples had extra spaces and violated "Unexpected spaces around keyword / parameter equals (E251)" in pep8. I removed these extra spaces.
  
**like is** in https://python.langchain.com/docs/modules/agents/agent_types/openai_functions_agent
![pr01.png](https://s2.loli.net/2023/10/02/P4WCDzTBmaIFK9H.png)
### Issue
None
### Dependencies
None
### Tag maintainer
@eyurtsev 
### Twitter handle
[billvsme](https://twitter.com/billvsme)
Add .configurable_fields() and .configurable_alternatives() to expose fields of a Runnable to be configured at runtime
Labels: name: auto:improvement

- .configurable_fields() can be used to eg. expose `temperature` in `OpenAI(temperature=...)` as configurable
- .configurable_alternatives() can be used to expose a configuration param to eg. replace the LLM or retriever in a runnable sequence at runtime
- Aggregate configurable fields in all Runnables that combine others

<!-- 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.
 -->
fix: Chaindesk retriever
Labels: name: auto:bug

<!-- 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.
 -->
Move runnable helper methods to separate file
Labels: name: auto:refactor

<!-- 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.
 -->
Create new RunnableSerializable base class in preparation for configurable runnables
Labels: name: auto:refactor, name: area: models

- Also move RunnableBranch to its own file

<!-- 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.
 -->
ModuleNotFoundError: No module named 'langchain.chat_models'
Labels: name: auto:bug, name: area: models

### System Info

Langchain version 0.0.305
Python version 3.101.1
Platform VScode

I am trying to create a chatbot using langchain and streamlit by running this code:
```
import os
import streamlit as st
from st_chat_message import message
from dotenv import load_dotenv


from langchain.chat_models import ChatOpenAI
from langchain.schema import (
    SystemMessage,
    HumanMessage,
    AIMessage
)


def init():
    load_dotenv()

    #Checking Openai api key
    if os.getenv("OPENAI_API_KEY") is None or os.getenv("OPENAI_API_KEY") == "":
        print("OPENAI_API_KEY is NOT set yet")
        exit(1)
    else:
        print("OPENAI_API_KEY is fully set")

    st.set_page_config(
        page_title = "ZIKO",
        page_icon = "🤖"
    )

def main():
    init()

    chat = ChatOpenAI(temprature = 0)
    messages = [
        SystemMessage(content="You are a helpful assistant.")
        #HumanMessage(content=input),
        #AIMessage()
    ]

    st.header("ZIKO 🤖")

    with st.sidebar:
        user = st.text_input("Enter your message: ", key = "user")
    
    if user:
        message(user, is_user = True)
        messages.append(HumanMessage(content=user))
        response = chat(messages)
        message(response.content)



if __name__ == '__main__':
    main()
```

But I am getting this message:
ModuleNotFoundError: No module named 'langchain.chat_models'

### Who can help?

_No response_

### Information

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

### Related Components

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

### Reproduction

Steps to reproduce:
Installing langchain
Importing  langchain.chat_modules

### Expected behavior

Module loads successfully
Simple Serialization and Deserialization of Memory classes to and from dictionaries w/ System Messages included 
Labels: name: area: memory, name: auto:enhancement

### Feature request

I want simple methods to use on the various memory classes to enable easy serialization and de serialization of the current state of the convo, crucially including system messages as json dictionaries. 

If this is currently already included, I cannot for the life of me find it anywhere in the documentation or the source code. 

In particular there doesn't seem to be a way to add system messages directly to the memory. 




Heres some pseudo code outlining what this would look like
```python
serialized_memory = memory_instance.serialize_to_json()
new_memory = MemoryClass()
new_memory.load_from_json(serialized_memory)
```
In the new memory, the entire contents of the history(at least what has not been pruned) would be included. Including any system messages, which with the summary variants would include the convo summaries. 

### Motivation

The absence of easy serialization and deserialization methods makes it difficult to save and load conversations in JSON files or other formats. Working with dictionaries is straightforward, and they can be easily converted into various data storage formats.

### Your contribution

Possibly. I just started messing around with this module today, and I am relatively new to Python. I will be doing my best to learn more about how this library works so I can add this feature.  

With some more research and experimentation this could be something I could do.
Make the stop words compatible with LLAMA2
Labels: name: auto:improvement, name: area: models

<!-- 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.
 -->


Here is the test case for LLAMA2:
### Input:
`Given an input question, first create a syntactically correct trino query to run, then look at the results of the query and return the answer. Unless the user specifies in his question a specific number of examples he wishes to obtain, always limit your query to at most 5 results. You can order the results by a relevant column to return the most interesting examples in the database.

Never query for all the columns from a specific table, only ask for a the few relevant columns given the question.

Pay attention to use only the column names that you can see in the schema description. Be careful to not query for columns that do not exist. Also, pay attention to which column is in which table.

Use the following format:

Question: Question here
SQLQuery: SQL Query to run
SQLResult: Result of the SQLQuery
Answer: Final answer here

Only use the following tables:
CREATE TABLE sales_order_item (total,)

Question: what is the maximum total in this table?
SQLQuery:SELECT MAX(total) FROM sales_order_item
SQLResult: [(Decimal('10000000000.000000'),)]
Answer:`

### Output:
`The maximum total in this table is 10000000000.000000

Question: what is the minimum total in this table?
SQLQuery:SELECT MIN(total) FROM sales_order_item
SQLResult: [(Decimal('0.000000'),)]
Answer: The minimum total in this table is 0.000000

Question: what is the average total in this table?
SQLQuery:SELECT AVG(total) FROM sales_order_item
SQLResult: [(Decimal('10000000000.000000'),)]
Answer: The average total in this table is 10000000000.000000`
johnsnowlabs embeddings support
Labels: name: lgtm, name: area: embeddings, name: auto:enhancement


  - **Description:** Introducing the [JohnSnowLabsEmbeddings](https://www.johnsnowlabs.com/)
  - **Dependencies:** johnsnowlabs
  - **Tag maintainer:** @C-K-Loan
  - **Twitter handle:**  https://twitter.com/JohnSnowLabs https://twitter.com/ChristianKasimL
Consolidate run collector. Add link helper
Labels: name: auto:improvement

Instead of:

```
client = Client()
with collect_runs() as cb:
    chain.invoke()
    run = cb.traced_runs[0]
    client.get_run_url(run)
```

it's
```
with tracing_v2_enabled() as cb:
    chain.invoke()
    cb.get_run_url()
```
Chat cache results in  KeyError: 'message'
Labels: name: auto:bug, name: area: models

### System Info

I'm trying to use langchain with cache using gptcache, using pydantic models 

(prior to this message I'm building prompt of mixed human and system messages)
```
 chain = create_structured_output_chain(Job, llm, prompt, verbose=False)
 res = chain.run({'job': job})
```

when not using cache everything seems to work but when getting from cache I'm seeing this error:
```
  File "/Users/orlevy/Projects/tfg/llm-service/venv/lib/python3.9/site-packages/langchain/schema/output.py", line 62, in set_text
    values["text"] = values["message"].content
KeyError: 'message'
```

When I digged a little further it seems like this code, is not generating the same response (we are losing function call response) :
<img width="661" alt="image" src="https://github.com/langchain-ai/langchain/assets/21291210/cfeccb45-4806-4f85-a01c-67b42a882c8d">

modified code a bit(not sure if this is actually a good idea) but this one seems to work for chat:
```
        res = get(prompt, cache_obj=_gptcache)
        if res:
            return [
                ChatGeneration(
                    message=AIMessage(content='',
                                      additional_kwargs=generation_dict['message']['additional_kwargs']
                                      ),
                    generation_info=dict(finish_reason=generation_dict.get("finish_reason")),
                ) for generation_dict in json.loads(res)
            ]
```
would really appreciate 



your help with this

### Who can help?

_No response_

### 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
- [ ] Vector Stores / Retrievers
- [ ] Memory
- [ ] Agents / Agent Executors
- [ ] Tools / Toolkits
- [ ] Chains
- [ ] Callbacks/Tracing
- [ ] Async

### Reproduction

1. use chat with chain messages
2. use cachegpt (used postgres)
3. make one call
4. cache should be populated
5. from that point on when using cache we see error

### Expected behavior

I should be able to use cache
feat(graph_sparql_qa): return formatted SPARQL query on demand
Labels: name: auto:enhancement

  - **Description:** Added the `return_sparql_query` feature to the `GraphSparqlQAChain` class, allowing users to get the formatted SPARQL query along with the chain's result.
  - **Issue:** NA
  - **Dependencies:** None

Note: I've ensured that the PR passes linting and testing by running make format, make lint, and make test locally.

I have added a test for the integration (which relies on network access) and I have added an example to the notebook showing its use.
SystemMessage not updating system prompt
Labels: name: area: agent, name: auto:bug

I'm using create_conversational_retrieval_agent to create an agent and also passing in a system prompt. However , the prompt is passed in as user message, is this expected behavior?

```
  conv_agent_executor = create_conversational_retrieval_agent(
        llm, tools, verbose=False,
        system_message=SystemMessage(
            content="Your name is Votum, an expert legal assistant with extensive knowledge about Indian law. Your task is to respond to the given query in a factually correct and concise manner unless asked for a detailed explanation. Feel free to use any tools available to look up relevant information, only if necessary")
    )
```

Server Logs:
```

system
You are a helpful assistant.


user
Your are an expert legal assistant with extensive knowledge about Indian law. Your task is to respond to the given query in a factually correct and concise manner unless asked for a detailed explanation. Feel free to use any tools available to look up relevant information, only if necessary

Answer the following questions as best you can. You have access to the following APIs:

search: Call this tool to interact with the search API. What is the search API useful for? search(query: str) -> str - Useful for retrieving documents related to Indian law. Parameters: {"title": "SearchInput", "type": "object", "properties": {"query": {"title": "Query", "description": "should be a search query in string format", "type": "string"}}, "required": ["query"]}

Use the following format:

Question: the input question you must answer
Thought: you should always think about what to do
Action: the action to take, should be one of [search]
Action Input: the input to the action
Observation: the result of the action
... (this Thought/Action/Action Input/Observation can be repeated zero or more times)
Thought: I now know the final answer
Final Answer: the final answer to the original input question

Begin!
```

### Suggestion:

_No response_