delayedkarma/langchain-issues huggingface dataset:
Fix return metadata when searching for DingoDB
Labels: name: area: vector store, name: auto:improvement

<!-- Thank you for contributing to LangChain!

Replace this entire comment with:
  - **Description:** a description of the change, 
  - **Issue:** the issue # it fixes (if applicable),
  - **Dependencies:** any dependencies required for this change,
  - **Tag maintainer:** for a quicker response, tag the relevant maintainer (see below),
  - **Twitter handle:** we announce bigger features on Twitter. If your PR gets announced, and you'd like a mention, we'll gladly shout you out!

Please make sure your PR is passing linting and testing before submitting. Run `make format`, `make lint` and `make test` to check this locally.

See contribution guidelines for more information on how to write/run tests, lint, etc: 
https://github.com/langchain-ai/langchain/blob/master/.github/CONTRIBUTING.md

If you're adding a new integration, please include:
  1. a test for the integration, preferably unit tests that do not rely on network access,
  2. an example notebook showing its use. It lives in `docs/extras` directory.

If no one reviews your PR within a few days, please @-mention one of @baskaryan, @eyurtsev, @hwchase17.
 -->
PGVector: support for concurrency
Labels: name: area: vector store, name: auto:improvement

### Feature request

When trying to concurrently fetch many collections from a single postgres server using PGVector, this will currently produce this error:
``` 
(psycopg2.errors.InternalError_) tuple concurrently updated
```

This is the expected behaviour for the code as it is and is produced by this line:
```
statement = sqlalchemy.text("CREATE EXTENSION IF NOT EXISTS vector")
```

There is no support for concurrent `CREATE EXTENSION` Operations in Postgres, as outlined in [this post](https://www.postgresql.org/message-id/3473.1393693757%40sss.pgh.pa.us):

> It'd be necessary to add some kind of locking scheme if you want to avoid "tuple concurrently updated" errors.  This is not really any different from the situation where two transactions both want to update the same row in a user table: unless the application takes extra steps to serialize the updates, you're going to get "tuple concurrently updated" errors. 
> 
> We do have such locking for DDL on tables/indexes, but the theory in the past has been that it's not worth the trouble for objects represented by single catalog rows, such as functions or roles.  You can't corrupt the database with concurrent updates on such a row, you'll just get a "tuple concurrently updated" error from all but the first-to-arrive update.

As the post suggests, if we want to concurrently run these statements, a locking Scheme is needed. This can easily be achieved by using Postgres' `pg_advisory_xact_lock`, as described [here](https://www.postgresql.org/docs/16/explicit-locking.html#ADVISORY-LOCKS) & [here](https://www.postgresql.org/docs/16/functions-admin.html):

``` 
BEGIN;
SELECT pg_advisory_xact_lock(1573678846307946496);
CREATE EXTENSION IF NOT EXISTS vector;
COMMIT;
``` 


This will acquire an exclusive transaction-level advisory lock, waiting if necessary which is automatically released at the end of the transaction. My proposal is therefore to change the current bare `CREATE EXTENSION IF NOT EXISTS vector` with the above to allow for concurrent execution without errors or having to retry.

### Motivation

We have a scenario where it would be beneficial to concurrently retrieve a large number of collections from a single server, and this would appear to be the easiest way to achieve this.

### Your contribution

I will submit an according PR.
bump 331
Labels: name: auto:nit

<!-- 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.
 -->
Example prompt for text classification
Labels: name: auto:question, name: area: models

Hi, could you please share me an working example for text classification using Langchain with LlamaCPP or llama-cpp-python module, when tried the following with Llama2 7B Q5_K_M

```
 prompt_template = """A message can be classified as one of the following categories: book, cancel, change.

Examples:
- Book: "I would like to book a room for two nights."
- Cancel: "Please cancel my reservation and refund the payment."
- Change: "I need to change the dates of my booking to next week."

Based on these categories, classify the following message:
```{text}```
"""
```

The LlamaCPP is as follows
```
llm = LlamaCpp(
    n_ctx=256,
    model_path=model,
    temperature=0,
    callback_manager=callback_manager,
    verbose=True,
)
```
result = run_query("I would like to cancel my booking and ask for a refund.", prompt_template, llm)

output:

> Please help me to solve this issue.
> Please assist in resolving the cancellation of the reservation as soon as possible.

The above sample is not classifying the given input.
fix regex pattern of structured output parser
Labels: name: area: agent, 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.
 -->

- **Description:**  fix the regex pattern of [StructuredChatOutputParser](https://github.com/langchain-ai/langchain/blob/master/libs/langchain/langchain/agents/structured_chat/output_parser.py#L18) and add unit tests for the code change.
- **Issue:** #12158 #12922
- **Dependencies:** None
- **Tag maintainer:** 
- **Twitter handle:** @hmdev3
- **NOTE:** This PR conflicts #7495 . After #7495 is merged, I am going to update PR.
Amazon Bedrock streaming not working with stop sequence
Labels: name: area: agent, name: auto:bug, name: area: models

### System Info


### Issue you'd like to raise.


Bedrock Streaming support was added in the [PR](https://github.com/langchain-ai/langchain/pull/10393/files#diff-9874347f7fa335df661ff4089b0922b3214e08a92e9879610424522f806358f7R62)

But there is an issue if streaming is enabled with `stop sequence`, See the below code, tailing comma is added to the `self.provider_stop_sequence_key_name_map.get(provider),`  which is causing 

```
"TypeError('keys must be str, int, float, bool or None, not tuple')"

line 35, in _prepare_input_and_invoke_stream
    body = json.dumps(input_body)


{'temperature': 0, 'max_tokens_to_sample': 4048, ('stop_sequences',): ['<observation>'], 'prompt': '\n\nHuman: 

```

```
        if stop:
            if provider not in self.provider_stop_sequence_key_name_map:
                raise ValueError(
                    f"Stop sequence key name for {provider} is not supported."
                )

            # stop sequence from _generate() overrides
            # stop sequences in the class attribute
            _model_kwargs[
                self.provider_stop_sequence_key_name_map.get(provider),
            ] = stop

```

### Suggested fix
Remove the trailing comma after `self.provider_stop_sequence_key_name_map.get(provider)` in the `_prepare_input_and_invoke_stream` method.

For example:
```
_model_kwargs[
    self.provider_stop_sequence_key_name_map.get(provider)
] = stop
```
This will resolve the TypeError and allow the stop sequence to be properly passed for streaming.





### Who can help?

cc @3coins @baskaryan @mukitmomi

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

### Reproduction

enable bedrock streaming with stop sequence. 

```

"TypeError('keys must be str, int, float, bool or None, not tuple')"

line 35, in _prepare_input_and_invoke_stream
    body = json.dumps(input_body)

{'temperature': 0, 'max_tokens_to_sample': 4048, ('stop_sequences',): ['<observation>'], 'prompt': '\n\nHuman: 

```




### Expected behavior

{'temperature': 0, 'max_tokens_to_sample': 4048, 'stop_sequences': ['<observation>'], 'prompt': '\n\nHuman: 


stop_sequences as str key.
Pandas data frame agent hallucinates when asking a quesry: Sending python code insted of actual result
Labels: name: area: agent, name: auto:bug

I created a pandas dataframe agent when i am querying over multiple csv files sometimes it is giving correct answer some time it is hallucinates by giving the python code to run to get the answer. 
Here's the response I am getting:
```
To determine the region with the highest total revenue, we can group the data by region and calculate the sum of the total revenue for each region. Then, we can find the region with the highest sum.

Here is the corresponding Python code to find the region with the highest total revenue, as well as the corresponding country and item type:

# Group the data by region and calculate the sum of total revenue for each region
region_revenue = df.groupby('Region')['Total Revenue'].sum()

# Find the region with the highest total revenue
highest_revenue_region = region_revenue.idxmax()

# Find the corresponding country and item type for the highest revenue region
corresponding_country = df[df['Region'] == highest_revenue_region]['Country'].iloc[0]
corresponding_item_type = df[df['Region'] == highest_revenue_region]['Item Type'].iloc[0]

highest_revenue_region, corresponding_country, corresponding_item_type

The region with the highest total revenue is Middle East and North Africa. The corresponding country is Azerbaijan and the corresponding item type is Snacks.
```
here is the agent i initiated:

```
create_pandas_dataframe_agent(
            ChatOpenAI(temperature=0.0, verbose=True,
                       model='gpt-3.5-turbo'
                       ),

            self.df,
            verbose=True,
            max_iterations=20,
            agent_type=AgentType.OPENAI_FUNCTIONS,
            # handle_parsing_errors=True,
            agent_executor_kwargs={
                "handle_parsing_errors": True
            }

        )

```
Do you think the chain is stopping in between before completing the response?
Issue: Unable to Merge confluence and githubissues loader
Labels: name: area: doc loader, name: auto:bug

Wanted to merge confluence and githubissue loader. But facing a problem as confluence loader requires additional arguments while loading. So, I am unable to use the MergedDataLoader here. 

Code:
loader = ConfluenceLoader(url="URL", username="USER", api_key="API")
loader1 = GitHubIssuesLoader(repo="REPO", access_token="TOKEN")
loader_all = MergedDataLoader(loaders=[loader1, loader])
documents = loader_all.load()
text_splitter = RecursiveCharacterTextSplitter(chunk_size=1000, chunk_overlap=0)

Error:
ValueError: Must specify at least one among `space_key`, `page_ids`, `label`, `cql` parameters.



### Suggestion:

_No response_
Issue: StructuredChatOutputParser regex may prevent agent's actions
Labels: name: area: agent, name: auto:bug

### System Info

Python == 3.11.3
Langchain == 0.0.330

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

### Reproduction

```bash
Python 3.11.3 (tags/v3.11.3:f3909b8, Apr  4 2023, 23:49:59) [MSC v.1934 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import langchain
>>> langchain.__version__
'0.0.330'
>>> from langchain.agents import load_tools, initialize_agent, AgentType
>>> from langchain.chains.conversation.memory import ConversationBufferMemory
>>> from langchain.chat_models import ChatOpenAI
>>> agent = initialize_agent(
...     agent=AgentType.STRUCTURED_CHAT_ZERO_SHOT_REACT_DESCRIPTION,
...     llm=ChatOpenAI(model='gpt-3.5-turbo', temperature=0),
...     memory=ConversationBufferMemory(),
...     verbose=True,
...     handle_parsing_errors=True,
...     tools=load_tools(tool_names=["requests_get"]),
... )
>>> agent.run('Search the latest version of python')


> Entering new AgentExecutor chain...
Thought: I can use the requests_get tool to search for the latest version of Python on the official Python website.

Action:
```{"action": "requests_get", "action_input": {"url": "https://www.python.org/downloads/"}}```

> Finished chain.
'Thought: I can use the requests_get tool to search for the latest version of Python on the official Python website.\n\nAction:\n```{"action": "requests_get", "action_input": {"url": "https://www.python.org/downloads/"}}```'
```

### Expected behavior

I expect agent to execute the action, `requests_get` in the above case.

NOTE: In the above case, InvalidRequestError would be raised after executing `requests_get` because the number of tokens is very large.

Related: #12158
Add ERNIE LLMs family supporting for the Chat-Model Agents
Labels: name: auto:enhancement, name: area: models, name: size:XS


  - **Description:** According to the document https://cloud.baidu.com/doc/WENXINWORKSHOP/s/clntwmv7t and https://cloud.baidu.com/doc/WENXINWORKSHOP/s/4lilb2lpf, add `ERNIE` LLMs family supporting for the *Chat-Model agents* such as `ChatAgent`, `ConversationalChatAgent`, `StructuredChatAgent`.  The chat message list limitations of the ERNIE large language model are as follows: 
      - It must have an odd number of members.
      - The role of the message in the message list must be `user`, `assistant`, and then `assistant` again.
Added support for filter out AWS Kendra search by score confidence
Labels: name: auto:improvement, name: integration: aws, name: size:M

 **Description:** It will add support for filter out kendra search by score confidence which will make result more accurate.
    For example
   ```
retriever = AmazonKendraRetriever(
        index_id=kendra_index_id, top_k=5, region_name=region,
        score_confidence="HIGH"
    )
```
Result will not include the records which has score confidence "LOW" or "MEDIUM". 
Relevant docs 
https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/kendra/client/query.html
https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/kendra/client/retrieve.html

 **Issue:** the issue # it resolve #11801 
**twitter:** [@SmitCode](https://twitter.com/SmitCode)
ChatTongyi do not support AsyncIteratorCallbackHandler 
Labels: name: auto:bug, name: area: models

### System Info

python 3.10.0
langchain 0.3.300

### Who can help?

@hwchase17
@agola11

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

ChatTongyi and  AsyncIteratorCallbackHandler  use togther

### Expected behavior

/Users/joeylin/Projects/questionAnswer/venv/lib/python3.10/site-packages/langchain/chat_models/tongyi.py:366: RuntimeWarning: coroutine 'AsyncCallbackManagerForLLMRun.on_llm_new_token' was never awaited
  run_manager.on_llm_new_token(chunk.text, chunk=chunk)
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
DocArrayInMemorySearch | Pydantic 2+ Breaking Changes
Labels: name: area: vector store, name: auto:bug

### System Info

langchain==0.0.330
Python 3.10.8

### Who can help?

@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

Was using latest release of pydantic (2.4.2).

getting errors to install langchain[docarray]

Above that:
ImportError: cannot import name 'ROOT_KEY' from 'pydantic.main' (...venv\lib\site-packages\pydantic\main.py)


Retried using pydantic 1.10.13. Works fine now. Not sure if worth adding to the error message or building in langchain dependence of pydantic version <2.0

I didn't try all the versions, but I know 2.4.2 breaks.

### Expected behavior

I wasn't able to set my index. Here is where the code broke:
index = VectorstoreIndexCreator(
    vectorstore_cls=DocArrayInMemorySearch
).from_loaders([loader])
subclassing VectorStoreRetriever causes unjustifiable infinite recursion
Labels: name: area: embeddings, name: area: vector store, name: auto:bug, name: area: models, name: integration: chroma

### System Info

Any system.

### Who can help?

_No response_

### Information

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

### Related Components

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

### Reproduction


```python


from typing import Any, Dict, List, Optional
from langchain.callbacks.manager import Callbacks
from langchain.embeddings import HuggingFaceEmbeddings
from langchain.vectorstores.chroma import Chroma
from langchain.schema.vectorstore import VectorStoreRetriever
from langchain.text_splitter import RecursiveCharacterTextSplitter
from langchain.chat_models import AzureChatOpenAI
from langchain.docstore.document import Document
import os


class MyRetriever(VectorStoreRetriever):
    def get_relevant_documents(self, query: str, *, callbacks: Callbacks = None, tags: List[str] | None = None, metadata: Dict[str, Any] | None = None, run_name: str | None = None, **kwargs: Any) -> List[Document]:
        print('Called get_relevant_documents in MyRetriever')
        res = super(MyRetriever, self).get_relevant_documents(query, callbacks=callbacks, tags=tags, metadata=metadata, run_name=run_name, **kwargs)
        print('Finished get_relevant_documents in MyRetriever')
        tmp_res: dict[str, Document] = {}
        for item in res:
            doc_name = item.page_content.split("\n", maxsplit=1)[0]
            if doc_name not in tmp_res:
                tmp_res[doc_name] = item
            else:
                orig_doc = tmp_res[doc_name]
                doc_content = "\n".join(item.page_content.split("\n")[1:])
                new_doc = Document(page_content=orig_doc.page_content + doc_content, metadata=orig_doc.metadata)
                tmp_res[doc_name] = new_doc
        return list(tmp_res.values())


embeddings = HuggingFaceEmbeddings(model_name="all-MiniLM-L6-v2")
vectordb = Chroma.from_documents([Document("blah")], embeddings, persist_directory="./tmp")
ret = MyRetriever(vectorstore=vectordb, tags=vectordb._get_retriever_tags())
ret.get_relevant_documents("blah")  # infinite recursion!

```

### Expected behavior

Safely call parent class method then customize its behaviour
docs: update hf pipeline docs
Labels: name: auto:documentation

- **Description:** Noticed that the Hugging Face Pipeline documentation was a bit out of date. 
Updated with information about passing in a pipeline directly (consistent with docstring) and a recent contribution of mine on adding support for multi-gpu specifications with Accelerate in 21eeba075c05714f185e5541f25228f7b555f606



<!-- 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.
 -->