delayedkarma/langchain-issues huggingface dataset:
langchain answers change drastically
Labels: name: area: embeddings, name: area: doc loader, name: area: vector store, name: auto:bug, name: auto:question, name: area: models

i have 1 folder called with data, in it there are 2 .txt files which are obama.txt and trump.txt, each file contains summary of each person from wikipedia and on the root of the folder, i have anthropic.py and below is the code

```
from langchain.document_loaders import DirectoryLoader
from langchain.indexes import VectorstoreIndexCreator
from langchain.embeddings import BedrockEmbeddings
from langchain.llms.bedrock import Bedrock

boto3_bedrock = boto3.client("bedrock-runtime")
llm = Bedrock(
    model_id="anthropic.claude-v2",
    client=boto3_bedrock,
    model_kwargs={"max_tokens_to_sample": 200},
)
bedrock_embeddings = BedrockEmbeddings(
    model_id="amazon.titan-embed-text-v1", client=boto3_bedrock
)

loader = DirectoryLoader("./data/", glob="*.txt")
index = VectorstoreIndexCreator(embedding=bedrock_embeddings).from_loaders([loader])
print(index.query("who is george washington", llm=llm))
```
as you can see i am using anthropic.claude-v2 LLM, and as for the query, i asked "who is george washington." during my first run, i got a response that describes who is george washington which shouldnt have happened because the code says to look for context provided only in obama.txt and trump.txt and george washington is not mentioned in either of them. However, when i re-run the code for the second time with **no changes** anywhere, i got a response saying that it does not know who is george washington which is what should have happened. Why is this the case?  Why the answers are different drastically when i run the code with 0 change? I attached a screenshot of the terminal output
![image](https://github.com/langchain-ai/langchain/assets/42351199/ac96ac3d-b088-4392-98e4-26c19d925cf6)


### Suggestion:

_No response_
Fix Fireworks Callbacks
Labels: name: auto:bug, name: area: models

I may be missing something but it seems like we inappropriately overrode the 'stream()' method, losing callbacks in the process. I don't think (?) it gave us anything in this case to customize it here?

See new trace:
https://smith.langchain.com/public/fbb82825-3a16-446b-8207-35622358db3b/r

and confirmed it streams.

Also fixes the stopwords issues from #12000
Overriding VectorstoreIndexCreator() embedding
Labels: name: area: embeddings, name: area: vector store, name: auto:question

This is the default class of VectorstoreIndexCreator

```
class VectorstoreIndexCreator(
    *,
    vectorstore_cls: type[VectorStore] = Chroma,
    embedding: Embeddings = OpenAIEmbeddings,
    text_splitter: TextSplitter = _get_default_text_splitter,
    vectorstore_kwargs: dict = dict
)
```

the default is to use OpenAIEmbeddings as its embedding. What i'm trying to do is to use BedrockEmbeddings, below is my code
```
loaders = TextLoader('data.txt')
index = VectorstoreIndexCreator(embedding=BedrockEmbeddings).from_loaders([loaders])
```
The error that i got
```
VectorstoreIndexCreator(embedding=BedrockEmbeddings).from_loaders([loaders])
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "pydantic\main.py", line 341, in pydantic.main.BaseModel.__init__
pydantic.error_wrappers.ValidationError: 1 validation error for VectorstoreIndexCreator
embedding
  instance of Embeddings expected (type=type_error.arbitrary_type; expected_arbitrary_type=Embeddings)
```
Fireworks: plumb stop words through for streaming
Labels: name: auto:bug, name: area: models

Fireworks was not plumbing through stop words for streaming (was for non streaming). Note that there is this other PR for the same llm that does not solve this problem and also seems to be missing stop words in some cases (I will leave a comment in the PR): https://github.com/langchain-ai/langchain/pull/11489

For now, this is a pretty bad issue preventing us from using non-chat models in fireworks so I appreciate a quick merge for this one. We are not blocked since we temporarily forked langchain but would like to unfork quickly.

Requesting review: @baskaryan et al
a bug fix for sagemaker endpoint streaming.
Labels: name: auto:bug, name: area: models, name: integration: aws

<!-- Thank you for contributing to LangChain!

Replace this entire comment with:
  - **Description:** bug fix for sagemakerendpoint streaming. 
  - **Issue:** the issue # it fixes sagemakerendpoint streaming modified line 341-350 to reflect. I've discovered a bug in the code from the recent sagemaker endpoint streaming.
Fixed it based on AWS code found here (https://aws.amazon.com/blogs/machine-learning/elevating-the-generative-ai-experience-introducing-streaming-support-in-amazon-sagemaker-hosting/)
  - **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 Alpha Vantage API Tool
Labels: name: auto:enhancement

### Feature request

We propose the integration of a new tool into Langchain that will provide comprehensive support for queries on the AlphaVantage Trading API. AlphaVantage offers a wide range of financial data and services, and this integration will enhance Langchain's capabilities for financial data analysis.

Here is the list of AlphaVantage APIs that will be integrated into the new tool:

- [TIME_SERIES_DAILY](https://www.alphavantage.co/documentation/#daily)
- [TIME_SERIES_WEEKLY](https://www.alphavantage.co/documentation/#weekly)
- [Quote Endpoint](https://www.alphavantage.co/documentation/#latestprice)
- [Search Endpoint](https://www.alphavantage.co/documentation/#symbolsearch)
- [Market News & Sentiment](https://www.alphavantage.co/documentation/#news-sentiment)
- [Top Gainers, Losers, and Most Actively Traded Tickers (US Market)](https://www.alphavantage.co/documentation/#gainer-loser)




### Motivation

The integration of AlphaVantage Trading API support in Langchain will provide users with access to a wealth of financial data, enabling them to perform in-depth analysis, develop trading strategies, and make informed financial decisions, all with real-time information



### Your contribution

I am a University of Toronto Student, working in a group and plan to submit a PR for this issue in November
added rrf argument in ApproxRetrievalStrategy class __init__()
Labels: name: lgtm, name: area: vector store, name: auto:improvement, name: integration: elasticsearch

  - **Description: To handle the hybrid search with RRF(Reciprocal Rank Fusion) in the Elasticsearch, rrf argument was added for adjusting 'rank_constant' and 'window_size' to combine multiple result sets with different relevance indicators into a single result set. (ref: https://www.elastic.co/kr/blog/whats-new-elastic-enterprise-search-8-9-0), 
  - **Issue:** the issue # it fixes (if applicable),
  - **Dependencies:** No dependencies changed,
  - **Tag maintainer:** @baskaryan,

Nice to meet you,
I'm a newbie for contributions and it's my first PR.

I only changed the langchain/vectorstores/elasticsearch.py file.
I did make format&lint 
I got this message,
```shell
make lint_diff  
./scripts/check_pydantic.sh .
./scripts/check_imports.sh
poetry run ruff .
[ "langchain/vectorstores/elasticsearch.py" = "" ] || poetry run black langchain/vectorstores/elasticsearch.py --check
All done! ✨ 🍰 ✨
1 file would be left unchanged.
[ "langchain/vectorstores/elasticsearch.py" = "" ] || poetry run mypy langchain/vectorstores/elasticsearch.py
langchain/__init__.py: error: Source file found twice under different module names: "mvp.nlp.langchain.libs.langchain.langchain" and "langchain"
Found 1 error in 1 file (errors prevented further checking)
make: *** [lint_diff] Error 2
```

Thank you
Issue: Which memory type i need to use for db-backed history 
Labels: name: area: memory, name: area: agent, name: auto:question

### Issue you'd like to raise.

I want to interact with my database so I'm using SQLDatabaseChain and SQL Agent to convert natural language query to sql query then execute on the database.
So I want to save the chat history here so that if a user asks anything related previous question/answer it should pick and then answer.
So my doubt is here what memory type I need to use.
Can you show me code example.

### Suggestion:

_No response_
ParentDocumentRetriever is incompatible with MultiVectorRetriever
Labels: name: area: vector store, name: auto:improvement

### System Info

**Description:**
It's not possible to use the ParentDocumentRetriever and MultiVectorRetriever at the same time.

But, it's a good idea to generate multiple vector for one fragment, then manage the life cycle of all vertions the ParentDocumentRetriever.

I think, the `MultiVectorRetriever` is not a good idea. I think it's better to create a MultiVectorStore to be compatible with all vectorstore interface. Then, it's possible to get a Retriever with vs.as_retriever()

I started to implement this scenario, but, because all my pull-request were never reads, I prefer not to submit any code and to maintain it endlessly.

### Who can help?

@eyurtsev

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

MultiVectorRetriever need a VectorStore.
But MultiVectorRetriever IS NOT a VectorStore.

### Expected behavior

An API to create multiple vectors for the same fragment, and, at the same time, a solution to manage all the vectors with the lifecycle of the original document.
If I remove/update the original document, all the associated vectors must be removed/updated.
ParentDocumentRetriever: parent_splitter and ids are incompatible
Labels: name: area: vector store, name: auto:bug, name: integration: chroma

### System Info

**description**
With parent_splitter, it's not possible to know the number of IDs before the split.
So, it's not possible to know the ID of each fragment.
Then, it's not possible to manage the life cycle of the fragment because it's impossible to know the list of IDs associated with the original big document.


### Who can help?

@eyurtsev

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

### Reproduction

```
from langchain.embeddings import OpenAIEmbeddings
from langchain.retrievers import ParentDocumentRetriever
from langchain.schema import Document
from langchain.storage import InMemoryStore
from langchain.text_splitter import RecursiveCharacterTextSplitter
from langchain.vectorstores.chroma import Chroma

vectorstore = Chroma(
    collection_name="full_documents",
    embedding_function=OpenAIEmbeddings()
)
store = InMemoryStore()

docs = [Document(page_content=txt, metadata={"id": id}) for txt, id in [("aaaaaa", 1), ("bbbbbb", 2)]]
ParentDocumentRetriever(
    vectorstore=vectorstore,
    docstore=store,
    id_key="id",
    parent_splitter=RecursiveCharacterTextSplitter(
        chunk_size = 2,
        chunk_overlap  = 0,
        length_function = len,
        add_start_index = True,
    ),
    child_splitter=RecursiveCharacterTextSplitter(
        chunk_size = 1,
        chunk_overlap  = 0,
        length_function = len,
        add_start_index = True,
    ),
).add_documents(docs,ids=[doc.metadata["id"] for doc in docs])
```
Produce:
```
ValueError: Got uneven list of documents and ids. If `ids` is provided, should be same length as `documents`.
```

### Expected behavior

No error.
how to connect to sql view in database  
Labels: name: auto:question, name: area: models

### System Info

latest version of langchain. python=3.11.4

### Who can help?

_No response_

### Information

- [ ] 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

How to connect to SQL view in the database, instead of using the all the tables from the DB, as the DB is huge(6Gb), I'm unable to get any out a correct output, I'm getting token error and when it is performing any join its unable to fetch a correct answer, but when I using a selected table its working efficiently in terms of accuracy and time taking. 

Can I get a appropriate method by which I can deal with the huge data without getting token or parser errors.
and how to work with the SQL views in the database.

here is the code for the connection string I have tried which includes the tables and its working fine,  

 from urllib.parse import quote_plus
driver = 'ODBC Driver 17 for SQL Server'
host = '########'
user = '#####'
database = 'HR_Git'
password = '#########' 
encoded_password = quote_plus(password)  

db = SQLDatabase.from_uri(f"mssql+pyodbc://{user}:{encoded_password}@{host}/{database}?driver={quote_plus(driver)}", include_tables = ['EGV_emp_departments'], sample_rows_in_table_info=2)

Thank you.

### Expected behavior

How to work with the SQL views inside the database and  way to avoid token and parser error.
UnstructuredEmailLoader just returning the first element
Labels: name: area: doc loader, name: auto:bug

# Issue:
 UnstructuredEmailLoader only returning first or no `element` of the mail irrespective of the `mode`.
### System Info

langchain version: 0.0.316
unstructured version: 0.10.18

### Who can help?

@eyurtsev 
@hwchase17 

### 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

 This is the [link](https://colab.research.google.com/drive/105l79buRBNsWelBIec0E1yUaowyfbVju?usp=sharing) to the code to regenerate the reponse

### Expected behavior

It should have returned the email's message text as the output with it's metadata
Issue: Doubt about Confluence Loader
Labels: name: area: doc loader, name: auto:question

### Issue you'd like to raise.

Hi!

I was taking a look to the Confluence integration at https://python.langchain.com/docs/integrations/document_loaders/confluence , and in our team we have the following doubt:
from langchain.document_loaders import ConfluenceLoader

loader = ConfluenceLoader(
    url="https://yoursite.atlassian.com/wiki",
    username="me",
    api_key="12345"
)
documents = loader.load(space_key="SPACE", include_attachments=True, limit=100, max_pages=800)
Can we fetch multiple space and generate embeddings at a time and do question answering from either of the space fetched by confluence loader?

### Suggestion:

_No response_
SeleniumURLLoader in Docker Container
Labels: name: auto:bug

### Issue you'd like to raise.

Hi developers, I am trying to run SeleniumURLLoader inside a Docker container.

When I tried to do a web-scraping on the URLs I am met with this error:

`ERROR MESSAGE: Message: Service /root/.cache/selenium/chromedriver/linux64/118.0.5993.70/chromedriver unexpectedly exited. Status code was: 127`

I tried running `update apt-get` and installed all the necessary dependencies, as well as running this command in the Dockerfile:

`RUN chmod +x /root/.cache/selenium/chromedriver/linux64/118.0.5993.70/chromedriver` but I was met with this error:

`chmod: cannot access '/root/.cache/selenium/chromedriver/linux64/118.0.5993.70/chromedriver': No such file or directory`

Any advice would be greatly appreciated.


### Suggestion:

_No response_
Make prompt validation opt-in
Labels: name: auto:improvement, name: area: models

By default replace input_variables with the correct value

<!-- 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 some transformers and a transformers pipeline
Labels: name: area: embeddings, name: auto:enhancement

**Description:**
As with `document_compressors`, it seems important to provide a pipeline for transformers.
The algorithm is different of `DocumentCompressorPipeline`. The idea is to have several transformers to apply to the same document, in order to have several embeddings for the same fragment (via a `ParentDocumentRetriever`). You therefore need to retrieve all the transformations, rather than chaining them together as `DocumentCompressorPipeline` does.

- `DocumentTransformerPipeline` is used when importing data into a vector store, to have multiple embedding for the same fragment. 
- `DocumentCompressorPipelinè is used when reading documents, to filter them.


Combined with this [pull-request](https://github.com/langchain-ai/langchain/pull/11968), it's easy to chain transformations while maintaining the link with the original document.

I propose 3 more transformers, to generate a summary and ask questions about the document.
The last one is a simple transformer without transformation. A simple copy of input to output.

I must explain the usage.

1. You split a big document to fragments
2. For each fragment, you want to generate a summary
3. For each fragment, you want to generate 3 questions, and generate a document one for each question
4. Then, you want to save the original fragment, the summary and the 3 questions in a vectorstore
5. You can use `ParentDocumentRetriever` to maintain the association with the original fragment.
6. When you use the `ParentDocumentRetriever`, all the embedding from the summary, the questions or the orginal fragment can select the same fragment.

But, `BaseDocumentTransformer` invoke a list of transformer to apply. If I use it with only the `SummarizeTransformer` and `GenerateQuestionsTransformer`, the result is composed with the summary and questions. But the original fragment are not in the result.

So the ̀`CopyDocumentTransformer` can add the original fragment.

Then, with `ParentDocumentVectorStore`, you can write:

```
vs = ParentDocumentVectorStore(
    vectorstore=vs,
    docstore=self.docstore,
    id_key=ID_KEY,
    parent_transformer=RecursiveCharacterTextSplitter(),
    child_transformer=DocumentTransformerPipeline(
        transformers=[
            GenerateQuestions.from_llm(llm),
            SummarizeTransformer.from_llm(llm),
            CopyDocumentTransformer(),
        ]
    ),
)
vs.add_documents(documents) # Split, summarize, ask questions and import
```
ConversationalRetrievalChain : make the condense_question chain choose the SelfQueryRetriever kwargs
Labels: name: area: vector store, name: auto:enhancement, name: area: models

### Feature request

Being able to set a SelfQueryRetriever's kwargs from the output of the Condese_question chain or any chain that runs just before.

### Motivation

The motivation behind this is enabling the ConversationalRetrievalChain based on a vectordb to tackle a big range of queries in a more specific way, for example:

- When asking about a specific topic, I want **k** kwarg to be no more than 10 and to have **lambda_mult** close to 0, meaning that documents taken from **fetch_k** should be similar.
- On the other hand when I am asking it to compare 2 entities I want **k** to be 20 for example and the **lambda_mult** to be really close to 1, meaning documents taken should have a little bit of variance

This will ensure that the passed context is good enough

### Your contribution

for now I am trying to output these variables from the condense_question sub chain, but I am not sure it's going to workout
Ensure dict() does not raise not implemented error, which should instead be raised in our custom method save()
Labels: name: area: agent, name: auto:bug

.dict() is a Pydantic method that cannot raise exceptions, as it is used eg. in `__eq__`

<!-- 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 ERNIE-Bot-4 model support for ErnieBotChat.
Labels: name: lgtm, name: auto:enhancement, name: area: models

- **Description:** According to the document https://cloud.baidu.com/doc/WENXINWORKSHOP/s/clntwmv7t, add ERNIE-Bot-4 model support for ErnieBotChat.
- **Dependencies:** Before using the ERNIE-Bot-4, you should have the model's access authority.