delayedkarma/langchain-issues huggingface dataset:
Add: USearch Vector Store
Labels: name: lgtm, name: area: vector store, name: auto:enhancement

## Description

I am excited to propose an integration with USearch, a lightweight vector-search engine available for both Python and JavaScript, among other languages.

## Dependencies

It introduces a new PyPi dependency - `usearch`. I am unsure if it must be added to the Poetry file, as this would make the PR too clunky. Please let me know.

## Profiles

- Maintainers: @ashvardanian @davvard
- Twitter handles: @ashvardanian @unum_cloud
Add Support for DingoDB as vectorstore
Labels: name: area: vector store, name: auto:enhancement

Description:
[DingoDB](https://dingodb.readthedocs.io/en/latest/) is a distributed multi-mode vector database, which combines the characteristics of data lakes and vector databases. It has real-time low-latency processing capabilities to achieve rapid insight and response, and can efficiently conduct instant analysis and process multi-modal data.

<!-- 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!

Please make sure you're PR is passing linting and testing before submitting. Run `make format`, `make lint` and `make test` to check this locally.

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
 -->
Agent using tool when it's not needed
Labels: name: area: agent, name: auto:bug

I initialized the  tool and  agent as following:
```
llm = ChatOpenAI(
    openai_api_key=OPENAI_API_KEY,
    model_name = 'gpt-3.5-turbo',
    temperature=0.0,
)

conversational_memory = ConversationBufferWindowMemory(
    memory_key='chat_history',
    k=6,
    return_messages=True
)

qa = RetrievalQA.from_chain_type(
    llm=llm,
    chain_type='stuff',
    retriever=vectorstore.as_retriever(),
)

tools = [
    Tool(
        name='Fressnapf Knowledge Base',
        func=qa.run,
        description=("""
        Only use this tool when you need to know more about Fressnapf service and products
        """)
    )
]

agent = initialize_agent(
    agent='chat-conversational-react-description',
    tools=tools,
    llm=llm,
    verbose=True,
    max_iterations=3,
    early_stopping_method='generate',
    memory=conversational_memory,
)
```

Now, when I'm asking the agent some basic questions he always uses the tool even if it's not useful to for answering the question.

After running `agent('Do you have ideas for a birthday gift?')` the agent directly uses the tool.
```
> Entering new AgentExecutor chain...
{
    "action": "Fressnapf Knowledge Base",
    "action_input": "birthday gift ideas"
}
Observation: Here are some birthday gift ideas:

1. Personalized photo album or picture frame
2. Spa or wellness gift set
3. Subscription to a favorite magazine or streaming service
4. Cooking or baking class
5. Outdoor adventure experience, such as a hiking or kayaking trip
6. Customized jewelry or accessories
7. Book or a set of books by their favorite author
8. Tickets to a concert, play, or sports event
9. A gift card to their favorite restaurant or store
10. A thoughtful handwritten letter or card expressing your love and appreciation.
Thought:{
    "action": "Final Answer",
    "action_input": "Here are some birthday gift ideas:\n\n1. Personalized photo album or picture frame\n2. Spa or wellness gift set\n3. Subscription to a favorite magazine or streaming service\n4. Cooking or baking class\n5. Outdoor adventure experience, such as a hiking or kayaking trip\n6. Customized jewelry or accessories\n7. Book or a set of books by their favorite author\n8. Tickets to a concert, play, or sports event\n9. A gift card to their favorite restaurant or store\n10. A thoughtful handwritten letter or card expressing your love and appreciation."
}
```

I've provided a very clear description for the tool and when the agent should be using it, but it seems like as if the agent ignoring my instructions.
Does anyone have any idea how to solve this issue?
Refine prompt modification
Labels: name: auto:improvement

### Feature request

I want to offer to change refine prompts to make a summary more correct.

### Motivation

In some cased (I can't say when exactly, but one time per 10-20) I saw that refine LLM added some additional text for summary.
Example:

> Since the provided context does not add any relevant information to the original summary, we will return the original summary:
> ... summary here...

On other cases I even saw output of refine prompt as:

>The existing summary is more comprehensive and provides a clear understanding of <my topic here>. The additional context provided does not contribute to the summary and can be disregarded.

As result I have this text as summary, but not my summary itself.

### Your contribution

I want to propose to use other prompts and check JSON result.

```
refine_initial_prompt_template = """\

Write a concise summary of the text (delimited with XML tags).
Please provide result in JSON format:
{{
    "summary": "summary here"
}}

<text>
{text}
</text>
"""

refine_combine_prompt_template = """\
Your job is to produce a final summary. We have provided an existing summary up to a certain point (delimited with XML tags).
We have the opportunity to refine the existing summary (only if needed) with some more context (delimited with XML tags).
Given the new context, refine the original summary (only if new context is useful) otherwise say that it's not useful.
Please provide result in JSON format:
{{
    "not_useful": "True if new context was not useful, False if new content was used",
    "refined_summary": "refined summary here if new context was useful"
}}

<existing_summary>
{existing_summary}
</existing_summary>

<more_context>
{more_context}
</more_context>
"""
```

Now I have JSON with field not_useful=True and can easy ignore it.
Feature/partial clearance buffer memory
Labels: name: area: memory, name: auto:improvement


  - Description: I ran into a problem several times that Conversation buffer memory gets full as soon as it reaches 4097 tokens. And we wouldn't want to completely clear the history as then the complete context would be lost. So I have added a method in **ChatMessageHistory** named **partial_clear** which takes an argument **delete_ratio**. If you pass 0.5 as delete_ratio it will remove 50% of the oldest messages in the memory. **BaseChatMemory** also inherits this method.
  - Issue: NA,
  - Dependencies: NA,
  - Tag maintainer: @hwchase17,
Add support for Xata as a vector store
Labels: name: area: vector store, name: auto:enhancement

This adds support for [Xata](https://xata.io) (data platform based on Postgres) as a vector store. We have recently added [Xata to Langchain.js](https://github.com/hwchase17/langchainjs/pull/2125) and would love to have the equivalent in the Python project as well.

The PR includes integration tests and a Jupyter notebook as docs. Please let me know if anything else would be needed or helpful.

I have added the xata python SDK as an optional dependency.

## To run the integration tests

You will need to create a DB in xata (see the docs), then run something like:

```
OPENAI_API_KEY=sk-... XATA_API_KEY=xau_... XATA_DB_URL='https://....xata.sh/db/langchain'  poetry run pytest tests/integration_tests/vectorstores/test_xata.py
```

<!-- 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!

Please make sure you're PR is passing linting and testing before submitting. Run `make format`, `make lint` and `make test` to check this locally.

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
 -->
How to pass a CSV file or a dataframe to Pandas REPL tool in Langchain?
Labels: name: area: agent, name: auto:question

I am trying to utilize Python Repl Tool in langchain with a CSV file and send me the answer based on the CSV file content. The problem is that it gets the action_input step of writing the code to execute right. However, it fails to answer because it couldn't determine the dataframe it should run the code on.

For example, I ask it about the longest name in a dataframe containing a column named "name" and it returns the following:

Entering new AgentExecutor chain...
{
    "action": "python_repl_ast",
    "action_input": "import pandas as pd\n\n# Assuming the dataset is stored in a pandas DataFrame called 'data'\nnames = data['NAMES']\nlongest_name = max(names, key=len)\nlongest_name"
}
Observation: NameError: name 'data' is not defined
Thought:{
    "action": "Final Answer",
    **"action_input": "I apologize for the confusion. Unfortunately, I do not have access to the dataset required to find the longest name. Is there anything else I can assist you with?"**
}


Is there a way to pass the dataframe object to the Pandas REPL tool in order for the code to execute properly and return me the answer? This problem is encountered while using the GPT-3.5-turbo API model.

This is the full code:

    ```
    df = pd.read_csv(file_path)

    tools = [PythonAstREPLTool(locals={"df": df})]

    agent = initialize_agent(
        agent='chat-conversational-react-description',
        tools=tools,
        llm=llm,
        verbose=True,
        max_iterations=3,
        early_stopping_method='generate',
        memory=conversational_memory
    )

    query = 'What is the longest name?'

    print(agent(query))

```
Issue:  Unstructured module nees backing off to lower ver. 0.7.12 seems ok
Labels: name: auto:bug

### Issue you'd like to raise.

guys if not already logged.. I had to uninstall unstructured module and  back it off to  lower ver. 0.7.12.    python3 -m pip install unstructured==0.7.12

### Suggestion:

maybe this needs attention ?
Issue: Conversation retreival chain : if current question is not at all related to prevoius chat history 
Labels: name: area: embeddings, name: area: vector store, name: auto:question

### Issue you'd like to raise.

How to handle such scenarios if the current asked questions is totally a new question and does not have relation with previous chat history . The standalone question would probably be non-sense, as it's semantic is twisted by the chat history.

`OPENAI_API_KEY=xxxxxx
OPENAI_API_BASE=https://xxxxxxxx.openai.azure.com/
OPENAI_API_VERSION=2023-05-15
import os
import openai
from dotenv import load_dotenv
from langchain.chat_models import AzureChatOpenAI
from langchain.embeddings import OpenAIEmbeddings

# Load environment variables (set OPENAI_API_KEY, OPENAI_API_BASE, and OPENAI_API_VERSION in .env)
load_dotenv()

# Configure OpenAI API
openai.api_type = "azure"
openai.api_base = os.getenv('OPENAI_API_BASE')
openai.api_key = os.getenv("OPENAI_API_KEY")
openai.api_version = os.getenv('OPENAI_API_VERSION')

# Initialize gpt-35-turbo and our embedding model
llm = AzureChatOpenAI(deployment_name="gpt-35-turbo")
embeddings = OpenAIEmbeddings(deployment_id="text-embedding-ada-002", chunk_size=1)
from langchain.document_loaders import DirectoryLoader
from langchain.document_loaders import TextLoader
from langchain.text_splitter import TokenTextSplitter

loader = DirectoryLoader('data/qna/', glob="*.txt", loader_cls=TextLoader, loader_kwargs={'autodetect_encoding': True})

documents = loader.load()
text_splitter = TokenTextSplitter(chunk_size=1000, chunk_overlap=0)
docs = text_splitter.split_documents(documents)
from langchain.vectorstores import FAISS
db = FAISS.from_documents(documents=docs, embedding=embeddings)

from langchain.chains import ConversationalRetrievalChain
from langchain.prompts import PromptTemplate

# Adapt if needed
CONDENSE_QUESTION_PROMPT = PromptTemplate.from_template("""Given the following conversation and a follow up question, rephrase the follow up question to be a standalone question.

Chat History:
{chat_history}
Follow Up Input: {question}
Standalone question:""")

qa = ConversationalRetrievalChain.from_llm(llm=llm,
                                           retriever=db.as_retriever(),
                                           condense_question_prompt=CONDENSE_QUESTION_PROMPT,
                                           return_source_documents=True,
                                           verbose=False)
`

### Suggestion:

_No response_
Object of type AgentAction is not JSON serializable
Labels: name: area: agent, name: auto:bug

### System Info

version 0.0.253

Running on a Jupyter Notebook in Google Colab

### Who can help?

_No response_

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

### Reproduction

Follow the steps in [Access Intermediate Steps](https://github.com/langchain-ai/langchain/blob/master/docs/extras/modules/agents/how_to/intermediate_steps.ipynb) within the Agent "How To".

The final step calls for 
`print(json.dumps(response["intermediate_steps"], indent=2))`

This is throwing the following error:
`TypeError: Object of type AgentAction is not JSON serializable`

Based on [this issue](https://github.com/langchain-ai/langchain/issues/2222) I think it may be happening following a recent upgrade.

### Expected behavior

Printing the intermediate steps as JSON.
Add missing tests for evaluation
Labels: name: auto:improvement

# What
- Add missing tests for evaluation

Replace this comment with:
  - Description: Add missing tests for evaluation
  - Issue: None
  - Dependencies: None
  - Tag maintainer: for a quicker response, tag the relevant maintainer (see below),
  - Twitter handle: @MLopsJ

Please make sure you're PR is passing linting and testing before submitting. Run `make format`, `make lint` and `make test` to check this locally.

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 exception inconsistencies
Labels: name: area: doc loader, name: auto:bug

# What
- This is to fix exception inconsistencies.

<!-- Thank you for contributing to LangChain!

Replace this comment with:
  - Description: fix exception inconsistencies
  - Issue: None
  - Dependencies: None
  - Tag maintainer: @baskaryan
  - Twitter handle: @MLopsJ

Please make sure you're PR is passing linting and testing before submitting. Run `make format`, `make lint` and `make test` to check this locally.

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 typo in long_context_reorder.ipynb
Labels: name: auto:documentation

begining -> beginning

<!-- 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!

Please make sure you're PR is passing linting and testing before submitting. Run `make format`, `make lint` and `make test` to check this locally.

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
 -->
feat(llms): add support for vLLM
Labels: name: lgtm, name: area: embeddings, name: auto:enhancement

Hello langchain maintainers, 
this PR aims at integrating [vllm](https://vllm.readthedocs.io/en/latest/#) into langchain. This PR closes #8729. 

This feature clearly depends on `vllm`, but I've seen other models supported here depend on packages that are not included in the pyproject.toml (e.g. `gpt4all`, `text-generation`) so I thought it was the case for this as well.

@hwchase17, @baskaryan

<!-- 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!

Please make sure you're PR is passing linting and testing before submitting. Run `make format`, `make lint` and `make test` to check this locally.

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
 -->
Enhanced functionality of PostgresChatMessageHistory
Labels: name: area: memory, name: auto:improvement

- Description : The PostgresChatMessageHistory will be more useful if it stores the timestamp of each message. While retrieving the messages, it is currently retrieved ordering it by session id. However, in an actual chat, the sessionid will be maintained for the duration of the chat. So, the messages will need to b retrieved after sorting it by the timestamp. The enhancement that I have pushed adds timestamp as a field in the table. Also added a function messages_order_by_time which orders the messages by timestamp(either desc or asc based on the parameter passed)
-  Issue: NA
- Dependencies: datetime package,
- Tag maintainer: @hwchase17
- Twitter handle: NA
Convenient filter pass to as_retriver() for vectorstores
Labels: name: area: vector store, name: auto:improvement

**Description:** Makes it more intuitive to pass filters to VectorStore Retrievers from `as_retriever`, by allowing for it to be passed as an argument separately from search_kwargs.

This is related to #7002, but I wouldn't resolve because that calls for taking all search arguments as direct keyword arguments, while this is currently only for filters. Other arguments seem to be mostly primitive types which aren't as unwieldy to pass as a dict- with the docstring it should hopefully be clearer how to pass those arguments.
How to pass multiple filters in db.get_relevant_documents()
Labels: name: area: doc loader, name: auto:question

I have three metadata: vehicle, color and city.
I want to retrieve chunks with filter -> vehicle = car, color = red and city = NY
All these conditions should be met in the retrieved chunks.

How can I do that?

results = db.get_relevant_documents(
                query=query,
                filter={"vehicle": "car", "color": "red", "city": "NY"},
)

But I am not getting desired results.