delayedkarma/langchain-issues huggingface dataset:
Weaviate - Fix schema existence check
Labels: name: lgtm, name: area: vector store, name: auto:bug

This will allow you create the schema beforehand.  The check was failing and preventing importing into existing classes.

<!-- 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.
 -->
Milvus wrapper doesn't support http URI
Labels: name: area: vector store, name: auto:bug

### System Info

```
langchain==0.0.315
pymilvus==2.3.0
Python 3.11.5
```

### Who can help?

@hwchase17 @agola11 

### 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

Minimal code to reproduce:

```python
from langchain.embeddings.base import Embeddings
from langchain.vectorstores import Milvus


class DummyEmbeddings(Embeddings):
    def embed_documents():
        return [[]]

    def embed_query(self):
        return []


if __name__ == "__main__":
    Milvus(
        embedding_function=DummyEmbeddings(),
        collection_name="foo",
        connection_args={
            "uri": "http://localhost:19530",
            "user": "",
            "password": "",
            "secure": False,
        },
    )
```

Running the code results in an exception coming from the [milvus adapter](https://github.com/langchain-ai/langchain/blob/5ae51a8a85d1a37ea98afeaf639a72ac74a50523/libs/langchain/langchain/vectorstores/milvus.py#L191)

```sh
> python -m milvus_reproduce
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "milvus_reproduce.py", line 14, in <module>
    Milvus(
  File ".venv/lib/python3.11/site-packages/langchain/vectorstores/milvus.py", line 155, in __init__
    self.alias = self._create_connection_alias(connection_args)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".venv/lib/python3.11/site-packages/langchain/vectorstores/milvus.py", line 191, in _create_connection_alias
    given_address = uri.split("https://")[1]
                    ~~~~~~~~~~~~~~~~~~~~~^^^
IndexError: list index out of range
```

### Expected behavior

The milvus adapter must allow for http uris.

The exception happens because the adapter assumes the uri always starts with `https://`. 

Instead one should parse url and get the netloc:

```python
from urllib import parse
given_address = parse.urlparse(uri).netloc
```

Similar to what `pymilvus` bindings [do](https://github.com/milvus-io/pymilvus/blob/master/pymilvus/orm/connections.py#L338).
Exception “I now know the final answer” thrown when using “create_pandas_df_agent”
Labels: name: area: agent, name: auto:bug, name: area: models

### System Info

I encountered an issue while using the create_pandas_df_agent function in LangChain to process data. When I asked a question about the data, an exception was thrown with the message “I now know the final answer”.

This phenomenon is not inevitable

model is  "gpt-3.5-turbo"




### Who can help?

_No response_

### Information

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

### Related Components

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

### Reproduction

`self.llm = AzureChatOpenAI(
            openai_api_base=self.api_base,
            openai_api_version=self.api_version,
            deployment_name=self.deployment_name,
            openai_api_key=self.api_token,
            openai_api_type="azure",
            max_tokens = self.max_tokens,
            model_name = self.model_name,
          )

self._dfagent = create_pandas_df_agent(self._llm.llm,df,verbose=True)

# tempt is a user problem
result = Result()
        try:
            res = self._dfagent.run(tempt)
            result.content = res
            result.status = 'success'
        except Exception as exception:
            result.error = (
                "Unfortunately, I was not able to answer your question, "
                "because of the following error:\n"
                f"\n{exception}\n"
            )
            result.status = 'error'
        return result`

### Expected behavior

I hope it returns the results normally
similarity_score_threshold not working as expected with ConversationalRetrievalChain
Labels: name: area: vector store, name: auto:bug, name: integration: pinecone

### System Info

LangChain version: langchain==0.0.327
Python version: Python 3.11.4
System: Windows 11 x64

### Who can help?

@hwchase17 @agola11 

### 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
- [X] Chains
- [ ] Callbacks/Tracing
- [ ] Async

### Reproduction

Here is my retriever-
```py
retriever = vectorstore.as_retriever(
    search_type="similarity_score_threshold",
    search_kwargs={
        "score_threshold": 0.8,
        "k": 5,
        "filter": {"source": {"$in": self.config.get("author")}},
    }
)
```

and chain-
```py
chain = ConversationalRetrievalChain.from_llm(
    llm=chat_model,
    retriever=retriever,
    memory=memory,
    chain_type="stuff",
    combine_docs_chain_kwargs={"prompt": prompt},
    get_chat_history=lambda h: h,
    condense_question_llm=ChatOpenAI(temperature=0.04),
    verbose=True,
)

```

In retriever, `similarity_score_threshold` is not working as expected. For now, I am using `0.8` as `score_threshold` for retriever. I am not getting any Documents in return.

However, this piece of code is giving me the expected Documents. Note that I am not specifying any score during similarity search. I am checking the score of each Document manually with 0.8 as a threshold.
```py
vectorstore.similarity_search_with_score(
    query=query,
    k=5,
    filter={"source": {"$in": self.config.get("author")}},
    namespace="my_namespace",
)
```

### Expected behavior

The below piece of codes should return the same Documents from Pinecone.

```py
retriever = vectorstore.as_retriever(
    search_type="similarity_score_threshold",
    search_kwargs={
        "score_threshold": 0.8,
        "k": 5,
        "filter": {"source": {"$in": self.config.get("author")}},
    }
)
```

```py
vectorstore.similarity_search_with_score(
    query=query,
    k=5,
    filter={"source": {"$in": self.config.get("author")}},
    namespace="my_namespace",
)
```
Issue: How can I utilize different histories for different users
Labels: name: area: memory, name: auto:question

### Issue you'd like to raise.

I am using the ConversationBufferWindowMemory class and I would like to have different memories for different users. So that each user has its individual memory. 

memory = ConversationBufferWindowMemory(k=3, memory_key="chat_history", return_messages=True)

qa = ConversationalRetrievalChain.from_llm(llm_model, vector_store.as_retriever(search_kwargs={'k': 2}), memory=memory, 

### Suggestion:

_No response_
CerebriumAI model_api_request deprecation
Labels: name: auto:bug, name: area: models

### System Info

Langchain 0.0.327
Python 3.10

### Who can help?

@hwchase17 or @eyurtsev are contributors of CerebriumAI based on Github history.

### Information

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

### Related Components

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

### Reproduction

Reference: https://docs.cerebrium.ai/cerebrium/cortex/examples/langchain

As a result it always returns

```Could not import cerebrium python package. Please install it with `pip install cerebrium`.```

as part of the following code

```
from cerebrium import model_api_request
        except ImportError:
            raise ValueError(
                "Could not import cerebrium python package. "
                "Please install it with `pip install cerebrium`."
            )
```

### Expected behavior

Returns value from the Cerebrium AI instance.
Cerebrium model_api_request deprecation
Labels: name: lgtm, name: auto:improvement, name: area: models, name: size:M

  - **Description:** As part of my conversation with Cerebrium team, `model_api_request` will be no longer available in cerebrium lib so it needs to be replaced. 
  - **Issue:** #12705 12705,
  - **Dependencies:** Cerebrium team (agreed)
  - **Tag maintainer:** @eyurtsev 
  - **Twitter handle:** No official Twitter account sorry :D
Fixed vertexai streaming with codey model
Labels: name: auto:bug, name: area: models

When using `codey` models in vertexai there is no candidate_count parameter in default_params and it is not required in kwargs too. Need to use full syntax dict.pop(key, default).

<!-- 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.
 -->
DOC: BaseCallbackHandler vs BaseTracer
Labels: name: area: doc loader, name: auto:question, name: auto:documentation

### Issue with current documentation:

While reviewing the document, I am learning about the callback functionality of langchain and have a question.

In langchain.callbacks, there are two classes: `BaseCallbackHandler` and `BaseTracer`. 

From what I can see in the document, it seems like the roles of these two classes are similar. 

Could you please provide an explanation of the differences between these two classes and clarify when it is appropriate to inherit from each class when creating a custom callback?

### Idea or request for content:

_No response_
Issue: Pinecone Vector Store incorrectly assigns score in similarity_search_with_relevance_scores
Labels: name: area: vector store, name: auto:bug, name: integration: pinecone

### Issue you'd like to raise.

With the Pinecone index setup with `cosine` metric, so the scores received from the vector database are already in the`cosine` metric.

However, the `_select_relevance_score_fn` of langchain pinecone vector store returns the base vector store's `_cosine_relevance_score_fn` for the `cosine` distance strategy.

https://github.com/langchain-ai/langchain/blob/b2138508cbf17aef3a08cdce072d79fd5dc63dc3/libs/langchain/langchain/vectorstores/pinecone.py#L231

In the base vector store implementation of `_cosine_relevance_score_fn` the score is the complement.

https://github.com/langchain-ai/langchain/blob/master/libs/langchain/langchain/schema/vectorstore.py#L187

So the cosine metric of 0.81 returned by the pinecone vector database indicating a higher similarity is turned into 0.19 in langchain and processed as very low similarity.

### Suggestion:

_No response_
ChatTongyi class  use  _generate method as async call and result in replying text dispeared
Labels: name: auto:bug, name: area: models

### System Info

langchain 0.0.327

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

it is easy to reproduction
use AsyncIteratorCallbackHandler() to get ChatTongyi stream data, 
it only get warning: 
`/venv/lib/python3.10/site-packages/langchain/chat_models/tongyi.py:365: RuntimeWarning: coroutine 'AsyncCallbackManagerForLLMRun.on_llm_new_token' was never awaited
  run_manager.on_llm_new_token(chunk.content, chunk=chunk)`
and the reply text dispeared

I look into the code , and find the problem is in the _agenerate() with only using _generate()
![image](https://github.com/langchain-ai/langchain/assets/2030833/ee37d1c0-3824-4932-91f0-3e0c1aafe61f)

we can see, the stream functionality in _generate() is incomplete and problematic. One of them is the questionable support for asynchronous callback, 
![image](https://github.com/langchain-ai/langchain/assets/2030833/84a3e1a9-f936-4002-aea3-889afbd618f8)
and this is where error happens
![image](https://github.com/langchain-ai/langchain/assets/2030833/070b61ad-d6ad-4aaf-ac3f-1f6f116942db)
it should use _astream()

pls, fix it , thx





### Expected behavior

return stream data
DOC: RetrievalQA.from_chain_type batch inference with elastic vectorstore
Labels: name: area: embeddings, name: area: vector store, name: auto:improvement, name: auto:documentation, name: area: models, name: integration: elasticsearch

### Issue with current documentation:

I have searched for a while but there is no example for RetrievalQA batch inference. For example, here is my code:

`model_name = "sentence-transformers/paraphrase-multilingual-mpnet-base-v2"

embeddings = HuggingFaceEmbeddings(model_name=model_name)

db = ElasticVectorSearch(
        embedding = embeddings,
        elasticsearch_url="http://localhost:9200",
        index_name="test_index",
    )
model = transformers.AutoModelForCausalLM.from_pretrained('vilm/vietcuna-7b-v3')
generate_text = transformers.pipeline(
    model=model, 
    tokenizer=tokenizer,
    batch_size = 8,
    return_full_text=True,  
    task='text-generation',
    stopping_criteria=stopping_criteria, 
    temperature=0,  
    max_new_tokens=512, 
    repetition_penalty=1.1
)

model_id = 'vilm/vietcuna-7b-v3'
llm = HuggingFacePipeline(pipeline=generate_text)

qa = RetrievalQA.from_chain_type(
    llm=llm,
    chain_type="stuff",
    retriever=db.as_retriever(),
    verbose=True,
    return_source_documents=True,
)
`

then I tried:
`qa.batch(inputs=[{'query':'Who is the prime minister of Vietnam'},{'query':'what is desease?'}])`
and
`qa(inputs=[{'query':'Who is the prime minister of Vietnam'},{'query':'what is desease?'}])`
Both failed. I saw the reason is ElasticVectorSearch cannot return two source documents at the same time. But the main problem is that is there any way to get RetrievalQA do batch inferencing with GPU utilization. LLM batch inference is easy to use (defined params) but it seems like the RetrievalQA chain hasn't supported this. 


### Idea or request for content:

_No response_
Add possibility to pass on_artifacts for a specific conversation
Labels: name: auto:improvement

Possibility to pass on_artifacts to a conversation. It can be then achieved by adding this way:

```python
result = agent.run(
    input=message.text,
    metadata={
        "on_artifact": CALLBACK_FUNCTION
    },
)
```

<!-- 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.
 -->
Local var ref in PALChain.from_math_prompt
Labels: name: auto:bug, name: area: models

### System Info

Python 3.10.12
langchain [v0.0.327](https://github.com/langchain-ai/langchain/releases/tag/v0.0.327)

### Who can help?

@agola

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

### Reproduction

<img width="909" alt="image" src="https://github.com/langchain-ai/langchain/assets/18315/ed391f1c-fda6-45bb-9ca6-002e99eb6782">


### Expected behavior

The right answer?
Lint Python notebooks with ruff.
Labels: name: auto:nit

The new ruff version fixed the blocking bugs, and I was able to fairly easily us to a passing state: ruff fixed some issues on its own, I fixed a handful by hand, and I added a list of narrowly-targeted exclusions for files that are currently failing ruff rules that we probably should look into eventually.

I went pretty lenient on the docs / cookbooks rules, allowing dead code and such things. Perhaps in the future we may want to tighten the rules further, but this is already a good set of checks that found real issues and will prevent them going forward.
output parsed: Error: Failed to parse. Text: "10,0,0,....". Error: TypeError: text.trim is not a function
Labels: name: auto:bug, name: area: models

### System Info

I have this method that is trying to format the output of LLM:

```typescript
private async getOrderedTitles(titles: string[], question: string) {
    const outputParser = StructuredOutputParser.fromZodSchema(z.array(z.number().describe("The score for this title")));
    const llm = new OpenAI({ modelName: "gpt-3.5-turbo", openAIApiKey: this.openAIApiKey, temperature: 0 });
    const orderingChain = new LLMChain({
      llm,
      outputParser,
      prompt: new PromptTemplate({
        template: getSortingPromot(),
        inputVariables: ["question", "titles"],
        partialVariables: { format_instructions: outputParser.getFormatInstructions() },
      }),
    });
    const res = await orderingChain.call({ question, titles });
    return outputParser.parse(res.text);
  }
```

and the prompt is:

```
Give each title a score as to how relevant it is to this question: {question}
##########################################
Titles:
{titles}
##########################################
{format_instructions}
```

it fails with:
```
Error: Failed to parse. Text: "10,0,0,10,0,10,10,0,10,0,10,0,10,0,0". Error: TypeError: text.trim is not a function
```

### Who can help?

_No response_

### Information

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

### Related Components

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

### Reproduction

Above code is all that is needed to recreate the issue.

### Expected behavior

There is no obvious reason why it should be failiing
Add with score functions to MMR for chroma
Labels: name: area: vector store, name: auto:improvement, name: integration: chroma

## 📝 **Description**

This PR introduces two new functions to the Chroma vectorstore:

    max_marginal_relevance_search_by_vector_with_scores
    max_marginal_relevance_search_with_scores

These functions extend the existing Maximal Marginal Relevance (MMR) functionality. In addition to returning the most relevant documents, they also return their associated similarity scores. This added context enables further customization and is particularly useful for applications requiring more advanced sorting or filtering algorithms.



## 🎯 **Usecase**

The extended functionality will be especially beneficial for applications that require advanced sorting or filtering mechanisms. My specific use-case involves using a Reciprocal Rank Fusion (RRF) system across multiple queries on the same topic. The inclusion of similarity scores alongside documents facilitates this kind of advanced application.


## 🛠 **Dependencies**

None. This feature does not introduce any new dependencies.



## 👥 **Maintainers**

@rlancemartin, @eyurtsev, I would highly appreciate your feedback on these additions.
DOC: When using LCEL, how do I set verbose=True on a chain?
Labels: name: area: doc loader, name: auto:documentation, name: area: lcel

### Issue with current documentation:

I´m using https://python.langchain.com/docs/guides/debugging and https://python.langchain.com/docs/modules/chains/document/refine.

Somehow the documentation does not line up. How can I set verbose=True on a chain when using LCEL?

### Idea or request for content:

Add documentation on how to activate verbose logs on a chain when using LCEL.