delayedkarma/langchain-issues huggingface dataset:
added fix for key error: doc_id
Labels: name: lgtm, name: area: vector store, name: auto:bug, name: size:XS

<!-- Thank you for contributing to LangChain!

Please title your PR "<package>: <description>", where <package> is whichever of langchain, community, core, experimental, etc. is being modified.

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,
  - **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` from the root of the package you've modified to check this locally.

See contribution guidelines for more information on how to write/run tests, lint, etc: https://python.langchain.com/docs/contributing/

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/docs/integrations` directory.

If no one reviews your PR within a few days, please @-mention one of @baskaryan, @eyurtsev, @hwchase17.
 -->
FakeStreamingListLLM.astream() yields strings while ChatOpenAI yields AIMessageChunk
Labels: name: auto:bug, name: area: models

### System Info

```
langchain==0.0.352
langchain-community==0.0.6
langchain-core==0.1.3
```

Python `3.12.1` running inside Docker from `python:3.12-bookworm` on Linux.

### Who can help?

I have a FastAPI app that streams the output of an LLM. The app uses `langchain.chat_models.ChatOpenAI` at runtime, but during test I mock the LLM with `langchain.llms.fake.FakeStreamingListLLM`. However, when my app calls `.astream()` on each of them I'm getting different results:

- While `ChatOpenAI` yields instances of `AIMessageChunk`...
- `FakeStreamingListLLM` yields instances of strings.

This mismatch between the fake and the real class makes the fake unsuitable for some mocking purposes as the interface of `AIMessageChunk` is different from a `str`.

@baskaryan @agola11 

### Information

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

### Related Components

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

### Reproduction

See an snippet below on how to reproduce the output of strings within `ipython`:

```python
from langchain.llms.fake import FakeStreamingListLLM
import asyncio

async def pp(llm):
    async for chunk in llm.astream('some input'):
        yield(f"{type(chunk)}: {chunk}")

async def consume():
    results = []
    async for item in pp(FakeStreamingListLLM(responses=['a'])):
        results.append(item)
    return results

asyncio.run(consume())

# OUTPUT:
["<class 'str'>: a"]
```

### Expected behavior

I'd expect `FakeStreamingListLLM` to return instances of `AIMessageChunk` as the real chat model.
langchain: Fix for issue #14663
Labels: name: needs test, name: auto:bug, name: area: langserve, name: size:XS

 - **Description:** Update to tools.py to allow aliased tool inputs to be included in the _parse_input function output
  - **Issue:** This fixes [Issue #14663](https://github.com/langchain-ai/langchain/issues/14663)
  - **Twitter handle:** [@consultchrisq ](https://twitter.com/consultchrisq?lang=en)
infra: remove path filter on check_diffs
Labels: name: lgtm, name: auto:nit, name: size:XS

CI should run on https://github.com/langchain-ai/langchain/pull/15412

But github only checks first 300 files: https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#git-diff-comparisons

> Diffs are limited to 300 files. If there are files changed that aren't matched in the first 300 files returned by the filter, the workflow will not run. You may need to create more specific filters so that the workflow will run automatically.
Filter conditions are discarded when using multiple filter conditions in similarity_search_with_relevance_scores
Labels: name: area: vector store, name: auto:bug, name: integration: chroma

### System Info

Windows 10
Python 3.11.5
langchain==0.0.331

### 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 want to do a similarity search on a vectorstore created beforehand and use multiple filtering conditions. The relevant part of the code is as follows:

```
from langchain.vectorstores import Chroma
from langchain.embeddings import SentenceTransformerEmbeddings
import chromadb

db_path = "my_db"

embeddings = SentenceTransformerEmbeddings(cache_folder='intfloat/multilingual-e5-large')
chroma_client = chromadb.PersistentClient(path=db_path)
    
db= Chroma(persist_directory=db_path, embedding_function=embeddings, client=chroma_client)

query = "My query"

filtered = db.similarity_search_with_relevance_scores(k=5, query=query, filter={"key1":value1, "key2":value2})
```

When using one filtering condition like
```
filtered = db.similarity_search_with_relevance_scores(k=5, query=query, filter={"key1":value1})
```
the filtering condtion is applied and it works fine. But when using multiple conditions, neither of the conditions is applied.

How can I use multiple filtering conditions?

### Expected behavior

I would expect, that both conditions are applied either connected by an "and" or an "or".
docs, community[patch], experimental[patch], langchain[patch], cli[pa…
Labels: name: auto:refactor, name: area: models, name: template, name: size:L

…tch]: import models from community

ran
```bash
git grep -l 'from langchain\.chat_models' | xargs -L 1 sed -i '' "s/from\ langchain\.chat_models/from\ langchain_community.chat_models/g"
git grep -l 'from langchain\.llms' | xargs -L 1 sed -i '' "s/from\ langchain\.llms/from\ langchain_community.llms/g"
git grep -l 'from langchain\.embeddings' | xargs -L 1 sed -i '' "s/from\ langchain\.embeddings/from\ langchain_community.embeddings/g"
git checkout master libs/langchain/tests/unit_tests/llms
git checkout master libs/langchain/tests/unit_tests/chat_models
git checkout master libs/langchain/tests/unit_tests/embeddings/test_imports.py
make format
cd libs/langchain; make format
cd ../experimental; make format
cd ../core; make format
```
community: integrate with model Yuan2.0
Labels: name: lgtm, name: auto:enhancement, name: area: models, name: size:L

1. integrate with [`Yuan2.0`](https://github.com/IEIT-Yuan/Yuan-2.0/blob/main/README-EN.md)
2. update `langchain.llms`
3. add a new doc for [Yuan2.0 integration](docs/docs/integrations/llms/yuan2.ipynb)
langchain[patch], experimental[patch]: replace langchain.schema imports
Labels: name: auto:refactor, name: area: models, name: size:M

Import from core instead.

Ran:
```bash
git grep -l 'from langchain.schema\.output_parser' | xargs -L 1 sed -i '' "s/from\ langchain\.schema\.output_parser/from\ langchain_core.output_parsers/g"
git grep -l 'from langchain.schema\.messages' | xargs -L 1 sed -i '' "s/from\ langchain\.schema\.messages/from\ langchain_core.messages/g"
git grep -l 'from langchain.schema\.document' | xargs -L 1 sed -i '' "s/from\ langchain\.schema\.document/from\ langchain_core.documents/g"
git grep -l 'from langchain.schema\.runnable' | xargs -L 1 sed -i '' "s/from\ langchain\.schema\.runnable/from\ langchain_core.runnables/g"
git grep -l 'from langchain.schema\.vectorstore' | xargs -L 1 sed -i '' "s/from\ langchain\.schema\.vectorstore/from\ langchain_core.vectorstores/g"
git grep -l 'from langchain.schema\.language_model' | xargs -L 1 sed -i '' "s/from\ langchain\.schema\.language_model/from\ langchain_core.language_models/g"
git grep -l 'from langchain.schema\.embeddings' | xargs -L 1 sed -i '' "s/from\ langchain\.schema\.embeddings/from\ langchain_core.embeddings/g"
git grep -l 'from langchain.schema\.storage' | xargs -L 1 sed -i '' "s/from\ langchain\.schema\.storage/from\ langchain_core.stores/g"
git checkout master libs/langchain/tests/unit_tests/schema/
make format
cd libs/experimental
make format
cd ../langchain
make format
```
Feature request: Provide exception objects in fallback
Labels: name: auto:improvement, name: area: models, name: size:S

## Motivation

I have an increasingly complex chain of LLM calls, and I would like to be able to continue it even if some intermediate requests fail. For example, if a prompt requires 10 requests as input and 1 of them fails, I might just use an empty string for it and continue with the remaining 9 as input. The [fallbacks](https://python.langchain.com/docs/guides/fallbacks) mechanism seems to work well for this:

```python
chain.with_fallbacks([RunnableLambda(lambda input: "")])
```

However, currently the exception objects are not exposed to the fallback runnable. You can only specify the exception *types* to catch by using the `exceptions_to_handle=` option.

For example, say one of the requests produces the following error:

```python
BadRequestError('Error code: 400 - {\'error\': {\'message\': "This model\'s maximum context length is 16385 tokens. However, your messages resulted in 17351 tokens. Please reduce the length of the messages.", \'type\': \'invalid_request_error\', \'param\': \'messages\', \'code\': \'context_length_exceeded\'}}')
```

I'd like to be able to surface this in the UI, so that I know *why* the request is failing, and that it's not just a transient server error – even though I want the chain to continue executing with missing data.

## Suggested implementation

One solution I can see is changing `RunnableWithFallbacks` so that it passes the exception object into the `configurable` dictionary in the [config](https://python.langchain.com/docs/expression_language/how_to/configure) of the fallback runnables. This way you can obtain the exception like this:

```python
from langchain_core.runnables import RunnableLambda, RunnableConfig

def handle_error(input, config: RunnableConfig):
    exception = config['configurable']['exception']
    # Store the `exception` object somewhere so it can be surfaced to the user
    return ''

chain = chain.with_fallbacks([RunnableLambda(handle_error)])
```

I'm attaching a patch that implements this in the Python library. I've only tested the `ainvoke` change in my code. In particular, I don't know if code for the `batch`/`abatch` case is correct.
Issue: not able to replicate documentation results 
Labels: name: area: agent, name: auto:bug

### Issue you'd like to raise.

Hi! I am trying to replicate this tutorial https://python.langchain.com/docs/integrations/toolkits/playwright on Colab using the same code, only difference is i am using `ChatOpenAI(model_name="gpt-3.5-turbo", temperature=0)` instead of `ChatAnthropic(temperature=0)`. 
When i run the agent (`result = await agent_chain.arun("What are the headers on langchain.com?")`) instead of obtaining the full output showed in the documentation, i get:
> Entering new AgentExecutor chain...
I'll need to extract the headers from the langchain.com website. Let me do that for you.
Action:```navigate_browser```

> Finished chain.
I'll need to extract the headers from the langchain.com website. Let me do that for you.
Action:```navigate_browser```.

It seems the agent stops before returning the final answer, any guess on why this is happening? Thanks a lot

### Suggestion:

_No response_
Warning message- No embedding_function provided, using default embedding function: SentenceTransformerEmbeddingFunction || Chroma db
Labels: name: area: embeddings, name: auto:bug, name: integration: chroma

### System Info

langchain - 0.0.350
Python - 3.11
chromadb - 0.3.23
OS - Win 10

### Who can help?

@hwchase17 
@eyur

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

just updated the version from 0.0.330 to 350
used the same code to create a chromadb class -
and when using Chroma.from_docs(docs, embeddings) get this in output - 
No embedding_function provided, using default embedding function: SentenceTransformerEmbeddingFunction

### Expected behavior

The expected behavior shall be that the embedding function provided should be used to create the embeddings, 

The following is the fix for the issue -

line 129 should have a embedding_function passed instead of None
DOC: Resolve URL Navigation Issues - Trailing Slash Discrepancy
Labels: name: area: doc loader, name: auto:bug

### Issue with current documentation:

Links within the documentation fail to open when the URL lacks a trailing '/'. Notably, the links on the page indicated in the example URL below and other links across various pages result in `page not found` errors when the URL lacks a trailing '/'. It's crucial to clarify that both URLs below, with and without a trailing '/', point to the same page. The issue lies in the fact that links on the version without '/' do not open, giving a `page not found` error, whereas the version with '/' functions correctly without any error.

Example URL (without '/' at the end of the URL): [https://python.langchain.com/docs/modules/agents](https://python.langchain.com/docs/modules/agents)  
Example URL (with '/' at the end of the URL): [https://python.langchain.com/docs/modules/agents/](https://python.langchain.com/docs/modules/agents/)

### Idea or request for content:

- **Suggested Changes:**
  1. Investigate and address the issue causing links to fail when the URL lacks a trailing '/'.
  2. Implement a fix to ensure all links across the documentation open successfully, regardless of the presence or absence of a trailing '/' in the URL.

- **Steps to Reproduce:**
  1. Navigate to [Example URL without '/'](https://python.langchain.com/docs/modules/agents) in a web browser.
  2. Attempt to click on various links within the documentation, especially those that navigate to other pages.
  3. Observe the page not found errors when the URL lacks a trailing '/'.

- **Additional Context:**
  - This issue is consistent across multiple pages in the documentation.
  - The problem is observed on Chrome, Brave, Firefox, and Bing browsers.
  - Other browsers may also have this issue, but I haven't tested in them.
这个貌似是一个bug， 修改之后就好了
Labels: name: area: memory, name: auto:bug

### System Info

/Users/sunwenke/miniconda3/envs/langchain/bin/python /Users/sunwenke/workspace/yongxinApi/langchain/localopenai/sql.py 
Traceback (most recent call last):
  File "/Users/sunwenke/workspace/yongxinApi/langchain/localopenai/sql.py", line 8, in <module>
    entity_store = SQLiteEntityStore(db_file="/Users/sunwenke/workspace/yongxinApi/langchain/Chinook.db")
  File "/Users/sunwenke/miniconda3/envs/langchain/lib/python3.10/site-packages/langchain/memory/entity.py", line 256, in __init__
    self.conn = sqlite3.connect(db_file)
  File "/Users/sunwenke/miniconda3/envs/langchain/lib/python3.10/site-packages/pydantic/v1/main.py", line 357, in __setattr__
    raise ValueError(f'"{self.__class__.__name__}" object has no field "{name}"')
ValueError: "SQLiteEntityStore" object has no field "conn"


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

### Reproduction

from langchain.chains import ConversationChain
from langchain.llms import OpenAI
from langchain.memory import ConversationEntityMemory
from langchain.memory.entity import SQLiteEntityStore
from langchain.memory.prompt import ENTITY_MEMORY_CONVERSATION_TEMPLATE
from localopenai import llm

entity_store = SQLiteEntityStore(db_file="/Users/sunwenke/workspace/yongxinApi/langchain/Chinook.db")
memory = ConversationEntityMemory(llm=llm, entity_store=entity_store)
conversation = ConversationChain(
    llm=llm,
    prompt=ENTITY_MEMORY_CONVERSATION_TEMPLATE,
    memory=memory,
    verbose=True,
)

conversation.run("有多少员工")



### Expected behavior

class SQLiteEntityStore(BaseEntityStore):
    """SQLite-backed Entity store"""

    session_id: str = "default"
    table_name: str = "memory_store"

    def __init__(
        self,
        session_id: str = "default",
        db_file: str = "entities.db",
        table_name: str = "memory_store",
        *args: Any,
        **kwargs: Any,
    ):
        try:
            import sqlite3
        except ImportError:
            raise ImportError(
                "Could not import sqlite3 python package. "
                "Please install it with `pip install sqlite3`."
            )
        super().__init__(*args, **kwargs)
        self.conn = sqlite3.connect(db_file)
        self.session_id = session_id
        self.table_name = table_name
        self._create_table_if_not_exists()


        self.conn = sqlite3.connect(db_file) 属性不存在   需要 在当前类 添加conn属性
[Filter] Unable to filter dates with MongoDB
Labels: name: area: vector store, name: auto:bug

### System Info

Platform: `Mac M1`
Python: `3.8.18`
Lanchain: `0.0.350`



### 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

1. Install Lanchain
2. Execute the code:

``` python
from datetime import datetime
from datetime import timedelta
from langchain.vectorstores.mongodb_atlas import MongoDBAtlasVectorSearch
from langchain.embeddings import OpenAIEmbeddings
from langchain.chat_models.openai import ChatOpenAI
from langchain.chains import RetrievalQA


db_name = 'YOUR_DB_NAME'
collection_name = 'YOUR_COLLECTION_NAME'
db_connection_string = 'YOUR_STRING'

def perform_retrieval_qa(
    query: str,
    from_date: str = (datetime.now() - timedelta(days=6)).strftime("%Y-%m-%d"),
    to_date: str = datetime.now().strftime("%Y-%m-%d"),
):
    print(from_date, to_date)
    vector_search = MongoDBAtlasVectorSearch.from_connection_string(
        db_connection_string,
        f"{db_name}.{collection_name}",
        OpenAIEmbeddings(),
        index_name="default"
    )

    llm = ChatOpenAI(
        model="gpt-3.5-turbo",
        temperature=0)
    retrieval_qa_chain = RetrievalQA.from_chain_type(
        llm,
        retriever=vector_search.as_retriever(
            search_kwargs={
                'k': 70,
                'filter':{
                    'date': {
                        '$gte': from_date,
                        '$lte': to_date
                    }
                }
            },
        )
    )

    result = retrieval_qa_chain(
        {"query": query},
        return_only_outputs=True
    )

    return result["result"]
```

### Expected behavior

I wish the RAG should be performed with the records from the filtered dates ranges, but it is not happening. The filter is not applied and the RAG is performed with the entire data.
Issue: milvus collectoin load replica number
Labels: name: area: vector store, name: auto:improvement

### Issue you'd like to raise.

If i set the in-memory replica of milvus to 3 and then run the following code on langchain, the following error occurs.

```python3
    vector_db = Milvus.from_documents(
        docs,
        embeddings,
        collection_name=collection,
     )
```
> pymilvus.exceptions.MilvusException: <MilvusException: (code=1100, message=failed to load collection: can't change the replica number for loaded collection: expected=3, actual=1: invalid parameter)>

when i look at the langchain code, the `replica_number` is 1 as the default and cannot be handed over as a factor, can you improve this?

```python3
    def _load(self) -> None:
        """Load the collection if available."""
        from pymilvus import Collection

        if isinstance(self.col, Collection) and self._get_index() is not None:
            self.col.load()
```
```python3
    def load(
        self,
        partition_names: Optional[list] = None,
        replica_number: int = 1,
        timeout: Optional[float] = None,
        **kwargs,
    ):
```

### Suggestion:

Please modify the langchain so that the `replica_number` of the milvus load collection can be handed over as an argument
Issue:Issue regarding Memory implementation
Labels: name: area: memory, name: auto:question

### Issue you'd like to raise.

`from langchain.chains.question_answering import load_qa_chain
template = """
{Your_Prompt}

CONTEXT:
{context}

QUESTION:
{query}

CHAT HISTORY:
{chat_history}

ANSWER:
"""

prompt = PromptTemplate(input_variables=["chat_history", "query", "context"], template=template)
memory = ConversationBufferMemory(memory_key="chat_history", input_key="query")

chain = load_qa_chain(ChatOpenAI(temperature=0), chain_type="stuff", memory=memory, prompt=prompt)`
is the above code is correct? if correct then please let me know from where i will get chat_history variable?

### Suggestion:

_No response_