delayedkarma/langchain-issues huggingface dataset:
Trying to merge a list of FAISS vectorstores without modifying the original vectorstores, but deepcopy() fails
Labels: name: auto:bug

Hi: I'm trying to merge a list of `langchain.vectorstores.FAISS` objects to create a new (merged) vectorstore, but I still need the original (pre-merge) vectorstores intact.  I can use `x.merge_from(y)` which works great:

`merged_stores = reduce(lambda x, y: (z := x).merge_from(y) or z, stores)
`

but that modifies x in place, so my original list of vectorstores ends up with its first store containing a merge with all other elements of the list: which is not what I want.  So I tried using `deepcopy()` to make a temporary copy of the vectorstore I'm merging into:

`merged_stores = reduce(lambda x, y: (z := deepcopy(x)).merge_from(y) or z, stores)
`

which does exactly what I want.  However, I now find that when I use a Universal Sentence Encoder embedding in the original list of vectorstores I get an exception from `deepcopy()`:

`TypeError: cannot pickle '_thread.RLock' object`

Is there an obvious way for me to achieve this (non-destructive) merge without adding my own `FAISS.merge_from_as_copy()` method to the `langchain.vectorstores.FAISS` class?
Nested models & exclude fields
Labels: name: auto:improvement


Description:
Add functionalities to the parser and output formatter:
- Recursively retrieves fields from any nested models
- Takes an optional list of fields of the (nested) model(s) to be excluded.
- If any `required` fields are specified as excluded, the class will throw a warning and create a new Pydantic model is created for output instructions, and to parse against.

Dependencies: 
- `warnings`

Tag maintainer: 
@baskaryan 

Please let me know if I should satisfy any additional requirements! :)
update cube_semantic.py
Labels: name: auto:improvement

changed condition to  "continue" only if type == view or else get the cube,measure and dimension values from dict


  - Description: changed condition to  "continue" only if type == view or else get the cube,measure and dimension values 
                         from dictionary, 
  - Issue: the issue was that the condition type!=view will meet the condition and skip all iterations because of the "continue" thus not extracting cube_name,dimension and measures from the cube iterator,
  - Dependencies: no dependencies,
  - Tag maintainer: @rlancemartin, @eyurtsev,
  - Twitter handle: I am fine without any mention haha. 


If no one reviews your PR within a few days, feel free to @-mention the same people again.

See contribution guidelines for more information on how to write/run tests, lint, etc: https://github.com/hwchase17/langchain/blob/master/.github/CONTRIBUTING.md
 -->
docs(retrievers/get-started): Fix broken state_of_the_union.txt link
Labels: name: auto:documentation

Thank you for this awesome library.

- Description: Fix broken link in documentation 
- Issue:
  - https://python.langchain.com/docs/modules/data_connection/retrievers/#get-started
  - <img width="786" alt="image" src="https://github.com/hwchase17/langchain/assets/21273221/d8bd15dd-e73e-48b9-b034-2fdbcd0cbaea">
  - Click *here*, then see "File not found"
  - the URL: https://github.com/hwchase17/langchain/blob/master/docs/modules/state_of_the_union.txt
  - I think the right one is https://github.com/hwchase17/langchain/blob/master/docs/extras/modules/state_of_the_union.txt
- Dependencies: -
- Tag maintainer: @baskaryan
- Twitter handle: -

<!-- 
If no one reviews your PR within a few days, feel free to @-mention the same people again.
 -->
improve description of JinaChat
Labels: name: auto:nit, name: auto:documentation

very small doc string change in the `JinaChat` class.

@hwchase17, @baskaryan
Thank you.

<!-- Thank you for contributing to LangChain!

Replace this 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!

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.

Maintainer responsibilities:
  - General / Misc / if you don't know who to tag: @baskaryan
  - DataLoaders / VectorStores / Retrievers: @rlancemartin, @eyurtsev
  - Models / Prompts: @hwchase17, @baskaryan
  - Memory: @hwchase17
  - Agents / Tools / Toolkits: @hinthornw
  - Tracing / Callbacks: @agola11
  - Async: @agola11

If no one reviews your PR within a few days, feel free to @-mention the same people again.

See contribution guidelines for more information on how to write/run tests, lint, etc: https://github.com/hwchase17/langchain/blob/master/.github/CONTRIBUTING.md
 -->
added SerpAPIKWARGWrapper class to retrieve specific serapi search result values
Labels: name: needs documentation, name: auto:enhancement, name: auto:documentation

Replace this comment with:
  - Description: added SerpAPIKWARGWrapper class to retrieve specific search result values, 
  - Tag maintainer: @hinthornw,
  - Twitter handle: EdenEmarco177
  - 
If you're adding a new integration, please include:
  1. Done
  2. Had issues editing the notebook so in PyCharm community edition , is there anyone who can assist?

If no one reviews your PR within a few days, feel free to @-mention the same people again.
Enhance Makefile with 'format_diff' Option and Improved Readability
Labels: name: lgtm, name: auto:improvement, name: auto:nit

<!-- Thank you for contributing to LangChain!

Replace this 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!

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.

Maintainer responsibilities:
  - General / Misc / if you don't know who to tag: @baskaryan
  - DataLoaders / VectorStores / Retrievers: @rlancemartin, @eyurtsev
  - Models / Prompts: @hwchase17, @baskaryan
  - Memory: @hwchase17
  - Agents / Tools / Toolkits: @hinthornw
  - Tracing / Callbacks: @agola11
  - Async: @agola11

If no one reviews your PR within a few days, feel free to @-mention the same people again.

See contribution guidelines for more information on how to write/run tests, lint, etc: https://github.com/hwchase17/langchain/blob/master/.github/CONTRIBUTING.md
 -->


### Description:

This PR introduces a new option format_diff to the existing Makefile. This option allows us to apply the formatting tools (Black and isort) only to the changed Python and ipynb files since the last commit. This will make our development process more efficient as we only format the codes that we modify. Along with this change, comments were added to make the Makefile more understandable and maintainable.

### Issue:

N/A

### Dependencies:

Add dependency to black.

### Tag maintainer:

@baskaryan

### Twitter handle:

[kzk_maeda](https://twitter.com/kzk_maeda)
Update Mosaic endpoint input/output api
Labels: name: lgtm, name: auto:improvement

As noted in prior PRs (https://github.com/hwchase17/langchain/pull/6060, https://github.com/hwchase17/langchain/pull/7348), the input/output format has changed a few times as we've stabilized our inference API. This PR updates the API to the latest stable version as indicated in our docs: https://docs.mosaicml.com/en/latest/inference.html

The input format looks like this:

`{"inputs": [<prompt>]}
`

The output format looks like this:
`
{"outputs": [<output_text>]}
`

LLM Test:

<img width="772" alt="Screenshot 2023-08-16 at 6 20 12 PM" src="https://github.com/langchain-ai/langchain/assets/9680231/34c72823-9d04-455e-8faa-b48c72584a8c">

Embedding Test:

<img width="776" alt="Screenshot 2023-08-16 at 6 22 22 PM" src="https://github.com/langchain-ai/langchain/assets/9680231/b9d2559a-d029-435f-b354-0e3df78eeed3">


<!-- Thank you for contributing to LangChain!

Replace this 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!

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.

Maintainer responsibilities:
  - General / Misc / if you don't know who to tag: @baskaryan
  - DataLoaders / VectorStores / Retrievers: @rlancemartin, @eyurtsev
  - Models / Prompts: @hwchase17, @baskaryan
  - Memory: @hwchase17
  - Agents / Tools / Toolkits: @hinthornw
  - Tracing / Callbacks: @agola11
  - Async: @agola11

If no one reviews your PR within a few days, feel free to @-mention the same people again.

See contribution guidelines for more information on how to write/run tests, lint, etc: https://github.com/hwchase17/langchain/blob/master/.github/CONTRIBUTING.md
 -->
Fix HF endpoint returns blank for text-generation
Labels: name: auto:bug

Description: Current `_call` function in the `langchain.llms.HuggingFaceEndpoint` class truncates response when `task=text-generation`. Same error discussed a few days ago on Hugging Face: https://huggingface.co/tiiuae/falcon-40b-instruct/discussions/51
Issue: Fixes #7353 
Tag maintainer: @hwchase17 @baskaryan @hinthornw
Add the `name` and `arguments` from `function_call` to `on_llm_new_token` when `streaming=True`
Labels: name: auto:improvement

### Feature request

Add the `name` and `arguments` from `function_call` to `on_llm_new_token` when `streaming=True`.

Now it's getting called with an empty token several times and no way to retrieve the `function_call['arguments']`.

We need to add this to every llm/


### Motivation

I'm streaming my calls (user get's to see the output realtime) to an llm and I've decided to use function calls so I get a structured output. I want to show the user the results (one argument is `message`) but I cannot cause only the tokens from `content` are streamed. 

Using the plain openai api I can do this.

### Your contribution

I can contribute a PR to a model and some tests, but I need guidance, as what the API should be. As I understand only `chat_models.openai` should be modified.
ChromaDB score goes the wrong way
Labels: name: auto:bug

### System Info

> langchain==0.0.227
> langchainplus-sdk==0.0.20
> chromadb==0.3.26

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

I'm sorry, but I don't have the time to carve out a MRE right now. My take is that it's still better to report it than not to.

### Expected behavior

`similarity_search_with_score` returns the distance as expected, but `similarity_search_with_relevance_scores` gives the same values, so that the closest distances return the smallest values, even though the output of the latter function is supposed to be higher for vectors that are closer:

> `similarity_search_with_relevance_scores`
> Return docs and relevance scores in the range [0, 1].
> 0 is dissimilar, 1 is most similar.
Allow passing custom prompts to GraphIndexCreator
Labels: name: lgtm, name: auto:improvement

<!-- Thank you for contributing to LangChain!

Replace this 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!

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.

Maintainer responsibilities:
  - General / Misc / if you don't know who to tag: @baskaryan
  - DataLoaders / VectorStores / Retrievers: @rlancemartin, @eyurtsev
  - Models / Prompts: @hwchase17, @baskaryan
  - Memory: @hwchase17
  - Agents / Tools / Toolkits: @hinthornw
  - Tracing / Callbacks: @agola11
  - Async: @agola11

If no one reviews your PR within a few days, feel free to @-mention the same people again.

See contribution guidelines for more information on how to write/run tests, lint, etc: https://github.com/hwchase17/langchain/blob/master/.github/CONTRIBUTING.md
 -->
Add new types of document transformers
Labels: name: auto:enhancement, name: auto:improvement, name: auto:documentation

  - Description: Add two new document transformers that translates documents into different languages and converts documents into q&a format to improve vector search results. Uses OpenAI function calling via the [doctran](https://github.com/psychic-api/doctran/tree/main) library.
  - Issue: N/A
  - Dependencies: `doctran = "^0.0.5"`
  - Tag maintainer: @rlancemartin @eyurtsev @hwchase17 
  - Twitter handle: @psychicapi or @jfan001

Notes
- Adheres to the `DocumentTransformer` abstraction set by @dev2049 in #3182 
- refactored `EmbeddingsRedundantFilter` to put it in a file under a new `document_transformers` module
- Added basic docs for `DocumentInterrogator`, `DocumentTransformer` as well as the existing `EmbeddingsRedundantFilter`
Update the API Reference link in Streamlit integration docs
Labels: name: auto:documentation

This page:

https://python.langchain.com/docs/modules/callbacks/integrations/streamlit 

Has a bad API Reference link currently. This PR fixes it to the correct link. 

Also updates the embedded app link to https://langchain-mrkl.streamlit.app/ (better name) which is hosted in langchain-ai/streamlit-agent repo

cc @baskaryan @agola11
Passing VectorStoreRetriever arguments to VectorStoreIndexWrapper.query()
Labels: name: auto:improvement

### Feature request

I want to pass arguments to the retriever used in the `VectorStoreIndexWrapper` `query` and `query_with_sources` methods. Right now, those methods don't have any means of passing `VectorStoreRetriever` arguments into `vectorstore.as_retriever()`:

```
langchain/indexes/vectorstore.py


    def query(
        self, question: str, llm: Optional[BaseLanguageModel] = None, **kwargs: Any
    ) -> str:
        """Query the vectorstore."""
        llm = llm or OpenAI(temperature=0)
        chain = RetrievalQA.from_chain_type(
        --->llm, retriever=self.vectorstore.as_retriever(), **kwargs
        )
        return chain.run(question)

    def query_with_sources(
        self, question: str, llm: Optional[BaseLanguageModel] = None, **kwargs: Any
    ) -> dict:
        """Query the vectorstore and get back sources."""
        llm = llm or OpenAI(temperature=0)
        chain = RetrievalQAWithSourcesChain.from_chain_type(
        --->llm, retriever=self.vectorstore.as_retriever(), **kwargs
        )
        return chain({chain.question_key: question})
```

### Motivation

I can't input `VectorStoreRetriever` arguments such as `search_type` or `search_kwargs` into `VectorStoreIndexWrapper.query()`, but I would be able to do that via `VectorStore.as_retriever()`, which `query()` and `query_with_sources()` use anyway.

### Your contribution

If someone isn't already working on this, I can make this change and submit a PR.
How to load Vicuna-7b, Vicuna13-b and Falcon LLM's from langchain through ConversationalRetrievalChain function?
Labels: name: auto:question, name: auto:documentation

### Issue with current documentation:

Below is the code which i'm using for another model

```
from langchain.embeddings.openai import OpenAIEmbeddings
from langchain.text_splitter import RecursiveCharacterTextSplitter
from langchain.vectorstores import DocArrayInMemorySearch
from langchain.chains import ConversationalRetrievalChain
from langchain.chat_models import ChatOpenAI
from langchain.document_loaders import PyPDFLoader
from langchain.embeddings import HuggingFaceEmbeddings
import llama_cpp

 # create a chatbot chain. Memory is managed externally.
qa = ConversationalRetrievalChain.from_llm(
  llm=load_model(model_id="TheBloke/orca_mini_v2_7B-GGML", device_type="mps", model_basename="orca-mini-v2_7b.ggmlv3.q4_0.bin"),#ChatOpenAI(model_name=llm_name, temperature=0), 
  chain_type=chain_type, 
  retriever=retriever, 
  return_source_documents=True,
  return_generated_question=True,
)
```

I'm loading orca mini model with model_id and model_basename. How to load Vicuna7b, Vicuna13b and Falcon LLM's? And how to change the device type from mps to Cuda?

### Idea or request for content:

_No response_
Fortune Reporter trying to get in touch with Chase

### Issue you'd like to raise.

@hwchase17 There's been a reporter from Fortune who are in their words: "launching our A.I. 50 list later this month. LangChain is being considered for the list, and while I've tried to get in touch with Harrison and Ankush in as many ways as possible, I haven't been able to."

They've been trying to get in touch with @hwchase17 for weeks now.

Search for **bdanweiss** on the Discord group.

### Suggestion:

_No response_
Fix buggy output from GraphQAChain
Labels: name: auto:bug

fixes https://github.com/hwchase17/langchain/issues/7289
A simple fix of the buggy output of `graph_qa`. If we have several entities with triplets then the last entry of `triplets` for a given entity merges with the first entry of the `triplets` of the next entity.

## Example
```
from langchain.llms import OpenAI
from langchain.indexes import GraphIndexCreator
from langchain.chains import GraphQAChain
from langchain.prompts import PromptTemplate
import os

text = "Apple announced the Vision Pro in 2023."

openai_api_key = os.getenv("OPENAI_API_KEY")

index_creator = GraphIndexCreator(llm=OpenAI(openai_api_key=openai_api_key, temperature=0))
graph = index_creator.from_text(text)
chain = GraphQAChain.from_llm(
    OpenAI(temperature=0, openai_api_key=openai_api_key),
    graph=graph, 
    verbose=True
)

chain.run("When did Apple announce the Vision Pro?")

# output pre-fix
Entities Extracted:
Apple, Vision Pro
Full Context:
Apple announced Vision ProVision Pro was announced in 2023

> Finished chain.

# output post-fix
Entities Extracted:
Apple, Vision Pro
Full Context:
Apple announced Vision Pro
Vision Pro was announced in 2023


> Finished chain.

```


@baskaryan
from langchain.llms import OpenAI causing ImportError: cannot import name 'Protocol'
Labels: name: auto:bug

### System Info

from typing_extensions import Protocol
from langchain.llms import OpenAI
llm = OpenAI(model_name='text-davinci-003', temperature=0.7, max_tokens=512)
print(llm)
-----------------------------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-28-c0d04f63c5e1> in <module>
      1 get_ipython().system('pip install typing-extensions==4.3.0')
      2 from typing_extensions import Protocol
----> 3 from langchain.llms import OpenAI
      4 llm = OpenAI(model_name='text-davinci-003', temperature=0.7, max_tokens=512)
      5 print(llm)

~\anaconda3\envs\GPTLLM\lib\site-packages\langchain\__init__.py in <module>
      1 """Main entrypoint into package."""
      2 
----> 3 from importlib import metadata
      4 from typing import Optional
      5 

~\anaconda3\envs\GPTLLM\lib\importlib\metadata\__init__.py in <module>
     15 import collections
     16 
---> 17 from . import _adapters, _meta
     18 from ._collections import FreezableDefaultDict, Pair
     19 from ._functools import method_cache, pass_none

~\anaconda3\envs\GPTLLM\lib\importlib\metadata\_meta.py in <module>
----> 1 from typing import Any, Dict, Iterator, List, Protocol, TypeVar, Union
      2 
      3 
      4 _T = TypeVar("_T")
      5 

ImportError: cannot import name 'Protocol'

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

### Reproduction

from langchain.llms import OpenAI
llm = OpenAI(model_name='text-davinci-003', temperature=0.7, max_tokens=512)
print(llm)

### Expected behavior

OpenAI
Params:{model_name, temperature, max_tokens}
conversationalRetrievalChain - how to improve accuracy
Labels: name: auto:question

I am using conversational retrieval chain with memory, but I am getting incorrect answers for trivial questions. 
Any suggestions what can I do to improve the accuracy of the output? 

#memory = ConversationEntityMemory(llm=llm, return_messages=True)
memory=ConversationBufferMemory(memory_key="chat_history",output_key='answer')
chain = ConversationalRetrievalChain.from_llm(
llm = llm,
retriever=retriever,
memory=memory, 
get_chat_history=lambda h :h,
return_source_documents=True)


![memoryerror](https://github.com/hwchase17/langchain/assets/95228400/03142f3f-65ff-48ad-8890-e64856749a58)
feat: Add `UnstructuredTSVLoader`
Labels: name: auto:enhancement, name: auto:documentation

### Summary

Adds an `UnstructuredTSVLoader` for TSV files. Also updates the doc strings for `UnstructuredCSV` and `UnstructuredExcel` loaders.

### Testing

```python
from langchain.document_loaders.tsv import UnstructuredTSVLoader

loader = UnstructuredTSVLoader(
    file_path="example_data/mlb_teams_2012.csv", mode="elements"
)
docs = loader.load()
```

### Reviewers
  - @rlancemartin
  - @eyurtsev
  - @hwchase17
use youtube chapter as hints and metadata in the youtube loader
Labels: name: auto:enhancement

### Feature request

When using the youtube loader. I think it would be useful to take into account the chapters if present.

1. The chapter timecode could be used to know when to chunk. Any chunk inside a chapter timeframe could also contain the same "youtube_chapter_title" metadata.
2. The name of the chapter could added directly inside the transcript. For example as a markdown header. This could be useful for LLM to maintain context over time.

### Motivation

There are useful information present in the youtube chapter title and timecodes that could be of use to LLMs.

Summarizing transcripts would probably be of higher quality if headers are present rather than a huge wall of text.

Adding metadata is always a win.

### Your contribution

Unfortunately not able to help for the time being but wanted to get the idea out there.