delayedkarma/langchain-issues huggingface dataset:
Adding Marqo to vectorstore ecosystem
Labels: name: lgtm, name: area: vector store, name: auto:enhancement, name: auto:documentation

This PR brings in a vectorstore interface for [Marqo](https://www.marqo.ai/).

The Marqo vectorstore exposes some of Marqo's functionality in addition the the VectorStore base class. The Marqo vectorstore also makes the embedding parameter optional because inference for embeddings is an inherent part of Marqo.

Docs, notebook examples and integration tests included.

Related PR:
https://github.com/hwchase17/langchain/pull/2807
Issue:IndexError: list index out of range
Labels: name: auto:bug

### System Info

langchain-0.0.221
python-3.10.11

### Who can help?

_No response_

### Information

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

### Related Components

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

### Reproduction

from langchain.schema import Document
from langchain.vectorstores import FAISS

list_of_documents = [
    Document(page_content="foo", metadata=dict(page=1)),
    Document(page_content="bar", metadata=dict(page=1)),
    Document(page_content="foo", metadata=dict(page=2)),
    Document(page_content="barbar", metadata=dict(page=2)),
    Document(page_content="foo", metadata=dict(page=3)),
    Document(page_content="bar burr", metadata=dict(page=3)),
    Document(page_content="foo", metadata=dict(page=4)),
    Document(page_content="bar bruh", metadata=dict(page=4)),
]
db = FAISS.from_documents(list_of_documents, embeddings)

### Expected behavior

Now  i'm following the FAISS Similarity Search with filtering code example on official Website,which is on https://python.langchain.com/docs/modules/data_connection/vectorstores/integrations/faiss,an error occur:
IndexError                                Traceback (most recent call last)
Cell In[56], line 13
      2 from langchain.vectorstores import FAISS
      3 list_of_documents = [
      4     Document(page_content="foo", metadata=dict(page=1)),
      5     Document(page_content="bar", metadata=dict(page=1)),
   (...)
     11     Document(page_content="bar bruh", metadata=dict(page=4)),
     12 ]
---> 13 db = FAISS.from_documents(list_of_documents, embeddings)

File [d:\Python310\lib\site-packages\langchain\vectorstores\base.py:332](file:///D:/Python310/lib/site-packages/langchain/vectorstores/base.py:332), in VectorStore.from_documents(cls, documents, embedding, **kwargs)
    330 texts = [d.page_content for d in documents]
    331 metadatas = [d.metadata for d in documents]
--> 332 return cls.from_texts(texts, embedding, metadatas=metadatas, **kwargs)

File [d:\Python310\lib\site-packages\langchain\vectorstores\faiss.py:551](file:///D:/Python310/lib/site-packages/langchain/vectorstores/faiss.py:551), in FAISS.from_texts(cls, texts, embedding, metadatas, ids, **kwargs)
    525 @classmethod
    526 def from_texts(
    527     cls,
   (...)
    532     **kwargs: Any,
    533 ) -> FAISS:
    534     """Construct FAISS wrapper from raw documents.
...
--> 314     results[indices[i]].append(batched_embeddings[i])
    315     num_tokens_in_batch[indices[i]].append(len(tokens[i]))
    317 for i in range(len(texts)):

IndexError: list index out of range

How's that happened and how can i fix it?
Conversationalbuffermemory to maintain chathistory  
Labels: name: auto:bug

### Issue you'd like to raise.

I am using Conversationalbuffermemory to maintain chathistory here is my code i dont know why my chathistory not working properly if any update required in my code please let me know I am using this code in my api 

class Chatbot:
    def __init__(self):
        self.model = "gpt-3.5-turbo"

    async def generate_response(self, user, question):
        index = faiss.read_index("faiss_index/faisss_audien_new.index")
        print(index)
        with open("faiss_index/faisss_audien_new.pkl", "rb") as f:
            store = pickle.load(f)
        store.index = index
        retriever = store.as_retriever(search_kwargs=dict(k=1))
       memory = ConversationBufferMemory(retriever=retriever)
       

        llm = OpenAI(temperature=0, max_tokens=1500, model_name='gpt-3.5-turbo')  # Can be any valid LLM
        _DEFAULT_TEMPLATE = """
                        You are an AI girlfriend having a conversation with a human. Respond to all inputs in 50 words or less. Do not say you are an AI language model.


                        Relevant pieces of previous conversation:
                        {history}

                        (You do not need to use these pieces of information if not relevant)

                        Current conversation:
                        User: {input}
                        Kira AI:
                    """
        PROMPT = PromptTemplate(
            input_variables=["history", "input"], template=_DEFAULT_TEMPLATE
        )
        
        conversation_with_summary = ConversationChain(
            llm=llm,
            prompt=PROMPT,
            memory=memory,
            verbose=True
        )
        

        result = conversation_with_summary.predict(input=question)
        gpt_response = result
        print(gpt_response)

        return gpt_response

### Suggestion:

_No response_
DOC: Multiple callback handlers
Labels: name: auto:documentation

### Issue with current documentation:

Example no longer working (key not found in dict) due to api changes: https://python.langchain.com/docs/modules/callbacks/how_to/multiple_callbacks

### Idea or request for content:

Corrected Serialization in several places:

from typing import Dict, Union, Any, List

from langchain.callbacks.base import BaseCallbackHandler
from langchain.schema import AgentAction
from langchain.agents import AgentType, initialize_agent, load_tools
from langchain.callbacks import tracing_enabled
from langchain.llms import OpenAI


# First, define custom callback handler implementations
class MyCustomHandlerOne(BaseCallbackHandler):
    def on_llm_start(
        self, serialized: Dict[str, Any], prompts: List[str], **kwargs: Any
    ) -> Any:
        print(f"on_llm_start {serialized['id'][-1]}")

    def on_llm_new_token(self, token: str, **kwargs: Any) -> Any:
        print(f"on_new_token {token}")

    def on_llm_error(
        self, error: Union[Exception, KeyboardInterrupt], **kwargs: Any
    ) -> Any:
        """Run when LLM errors."""

    def on_chain_start(
        self, serialized: Dict[str, Any], inputs: Dict[str, Any], **kwargs: Any
    ) -> Any:
        print(f"on_chain_start {serialized['id'][-1]}")

    def on_tool_start(
        self, serialized: Dict[str, Any], input_str: str, **kwargs: Any
    ) -> Any:
        print(f"on_tool_start {serialized['name']}")

    def on_agent_action(self, action: AgentAction, **kwargs: Any) -> Any:
        print(f"on_agent_action {action}")


class MyCustomHandlerTwo(BaseCallbackHandler):
    def on_llm_start(
        self, serialized: Dict[str, Any], prompts: List[str], **kwargs: Any
    ) -> Any:
        print(f"on_llm_start (I'm the second handler!!) {serialized['id'][-1]}")


# Instantiate the handlers
handler1 = MyCustomHandlerOne()
handler2 = MyCustomHandlerTwo()

# Setup the agent. Only the `llm` will issue callbacks for handler2
llm = OpenAI(temperature=0, streaming=True, callbacks=[handler2])
tools = load_tools(["llm-math"], llm=llm)
agent = initialize_agent(tools, llm, agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION)

# Callbacks for handler1 will be issued by every object involved in the
# Agent execution (llm, llmchain, tool, agent executor)
agent.run("What is 2 raised to the 0.235 power?", callbacks=[handler1])
MultiQueryRetriever broken on master and needs tests
Labels: name: auto:bug, name: auto:documentation

### System Info

v0.0.221

### Who can help?

@vowelparrot 

### Information

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

### Related Components

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

### Reproduction

[MultiQueryRetriever](https://python.langchain.com/docs/modules/data_connection/retrievers/how_to/MultiQueryRetriever) is broken due to [5962](https://github.com/hwchase17/langchain/pull/5962) introducing a new method `_get_relevant_documents`.

Caught this b/c I no longer see expected logging when running example in [docs](https://python.langchain.com/docs/modules/data_connection/retrievers/how_to/MultiQueryRetriever).

```
unique_docs = retriever_from_llm.get_relevant_documents(query="What does the course say about regression?")
len(unique_docs)
```

For MultiQueryRetriever, get_relevant_documents does a few things (PR [here](https://github.com/hwchase17/langchain/pull/6833/files#diff-73c5e56610f556ddc4710db1b9da4c6277b8ffaef6d535e3cf1e1ceb4b22b186)).

E.g., it will run `queries = self.generate_queries(query, run_manager)` and log the queries.

It appears the method name has been changed to `_get_relevant_documents`?

And it now requires some additional args (e.g., `run_manager`)?

AFAICT, `get_relevant_documents` currently will just do retrieval w/o any of the `MultiQueryRetriever` logic.

If this is expected, then documentation will need to be updated for MultiQueryRetriever [here](https://python.langchain.com/docs/modules/data_connection/retrievers/how_to/MultiQueryRetriever) to use _get_relevant_documents and supply run_manager and explain what run_manager is.

Also this exposes that fact that we need a test for MultiQueryRetriever.

### Expected behavior

We should actually run the logic in `MultiQueryRetriever` as noted in the [PR](https://github.com/hwchase17/langchain/pull/6833/files#diff-73c5e56610f556ddc4710db1b9da4c6277b8ffaef6d535e3cf1e1ceb4b22b186).

```
    INFO:root:Generated queries: ["1. What is the course's perspective on regression?", '2. How does the course discuss regression?', '3. What information does the course provide about regression?']
```
OpenAIChat(streaming=True) donot work
Labels: name: auto:bug

### System Info

index = VectorstoreIndexCreator(vectorstore_cls=DocArrayInMemorySearch, embedding=embeddings) 
index = index.from_loaders([PyMuPDFLoader('孙子兵法.pdf')])
query = '孙子兵法的战略'
index.query(llm=OpenAIChat(streaming=True), question=query, chain_type="stuff")

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

### Reproduction

```
index = VectorstoreIndexCreator(vectorstore_cls=DocArrayInMemorySearch, embedding=embeddings) 
index = index.from_loaders([PyMuPDFLoader('孙子兵法.pdf')])
query = '孙子兵法的战略'
index.query(llm=OpenAIChat(streaming=True), question=query, chain_type="stuff")
```
streaming ...

### Expected behavior

```
index = VectorstoreIndexCreator(vectorstore_cls=DocArrayInMemorySearch, embedding=embeddings) 
index = index.from_loaders([PyMuPDFLoader('孙子兵法.pdf')])
query = '孙子兵法的战略'
index.query(llm=OpenAIChat(streaming=True), question=query, chain_type="stuff")
```
streaming ...
OPENAI_FUNCTIONS Agent Memory won't work inside of Streamlit st.chat_input element
Labels: name: auto:bug

### System Info

langchain = 0.0.218
python = 3.11.4

### Who can help?

@hwchase17 , @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
- [X] Memory
- [X] Agents / Agent Executors
- [ ] Tools / Toolkits
- [ ] Chains
- [ ] Callbacks/Tracing
- [ ] Async

### Reproduction

To reproduce:

1. Follow [Add Memory Open Ai Functions](https://python.langchain.com/docs/modules/agents/how_to/add_memory_openai_functions)
2. Import Streamlit
3. Create Chat Element using st.chat_input 
4. Try running agent through Streamlit

### Expected behavior

The agent memory works correctly when the Agent is called via ``` agent_chain.run("Insert prompt") ```  but when this is being done via a Streamlit Chat element like:

```python
if prompt := st.chat_input():
    st.session_state.messages.append({"role": "user", "content": prompt})
    st.chat_message("user").write(prompt)
    with st.spinner('Thinking...'):
        st_callback = StreamlitCallbackHandler(st.container())
        agent_chain.run(prompt, callbacks=[st_callback])
    st.chat_message("assistant").write(response)
    st.session_state.messages.append({"role": "assistant", "content": response})
``` 

It no longer works.
Chain.run() without any param will cause error
Labels: name: auto:bug

### System Info
Langchain 0.0.221
WSL
Python 3.11

###
If design a very simple chain which do not need any input parameters. Then run it, it will throw error. I think this without any input params may be useful.

    llm = conn.connecting.get_model_azureopenai()
    mem = langchain.memory.ConversationBufferMemory()
    msg1 = langchain.prompts.HumanMessagePromptTemplate.from_template("Hi there!")
    prompt1 = langchain.prompts.ChatPromptTemplate.from_messages([msg1])
    print(prompt1.input_variables)

    chain1 = langchain.chains.LLMChain(
        llm=llm,
        prompt=prompt1,
        memory=mem,
    )
    resp1 = chain1.run()
    print(resp1)

==================
Error:

/usr/local/miniconda3/bin/python /mnt/c/TechBuilder/AIML/LangChain/Dev20230701/chains/runchain1.py 
Traceback (most recent call last):
  File "/mnt/c/TechBuilder/AIML/LangChain/Dev20230701/chains/runchain1.py", line 87, in <module>
    run2()
  File "/mnt/c/TechBuilder/AIML/LangChain/Dev20230701/chains/runchain1.py", line 81, in run2
    resp1 = chain1.run()
            ^^^^^^^^^^^^
  File "/usr/local/miniconda3/lib/python3.11/site-packages/langchain/chains/base.py", line 296, in run
    raise ValueError(
ValueError: `run` supported with either positional arguments or keyword arguments, but none were provided.
[]

Process finished with exit code 1


### 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
- [ ] Vector Stores / Retrievers
- [ ] Memory
- [ ] Agents / Agent Executors
- [ ] Tools / Toolkits
- [X] Chains
- [ ] Callbacks/Tracing
- [ ] Async

### Reproduction

Step1, develop a simple chain

/usr/local/miniconda3/bin/python /mnt/c/TechBuilder/AIML/LangChain/Dev20230701/chains/runchain1.py 
Traceback (most recent call last):
  File "/mnt/c/TechBuilder/AIML/LangChain/Dev20230701/chains/runchain1.py", line 87, in <module>
    run2()
  File "/mnt/c/TechBuilder/AIML/LangChain/Dev20230701/chains/runchain1.py", line 81, in run2
    resp1 = chain1.run()
            ^^^^^^^^^^^^
  File "/usr/local/miniconda3/lib/python3.11/site-packages/langchain/chains/base.py", line 296, in run
    raise ValueError(
ValueError: `run` supported with either positional arguments or keyword arguments, but none were provided.
[]

Process finished with exit code 1


Step 2, run it without input params, because it does not need any input params.



### Expected behavior

Should run without error
get_openapi_chain fails to produce proper Openapi scheme when preparing url.
Labels: name: auto:bug

### System Info

langchain==0.0.221
langchainplus-sdk==0.0.19

Windows 10

### Who can help?

@dev2049 @homanp 

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

### Reproduction

1. install `langchain` with the aformentioned version
2. install `openai`
3. run the following code:
```py

import os
from langchain.chains.openai_functions.openapi import get_openapi_chain

os.environ['OPENAI_API_KEY'] = OPENAI_API_KEY

chain = get_openapi_chain("https://gptshop.bohita.com/openapi.yaml")
res = chain.run("I want a tight fitting red shirt for a man")
res

```
or this, as it will produce a similar error:
```py

import os
from langchain.chains.openai_functions.openapi import get_openapi_chain

os.environ['OPENAI_API_KEY'] = OPENAI_API_KEY

chain = get_openapi_chain("https://nani.ooo/openapi.json")
res = chain.run("Show me the amount of nodes on the ethereum blockchain")
res

```

### Expected behavior

The response dict. (not sure what that would look like as I have not gotten a successful response)
Buffer method of ConversationTokenBufferMemory should be able to return messages as string
Labels: name: lgtm, name: auto:improvement

### Description:
`ConversationBufferTokenMemory` should have a simple way of returning the conversation messages as a string.

Previously to complete this, you would only have the option to return memory as an array through the buffer method and call `get_buffer_string` by importing it from `langchain.schema`, or use the `load_memory_variables` method and key into `self.memory_key`.

### Maintainer
@hwchase17
Anthropic Upgrade issue
Labels: name: auto:bug

### System Info

Langchain version 0.0.221
Anthropic versions 0.3.1 and 0.3.2

Whenever using ChatAnthropic, this now appears. Version 0.2.10 works, but the below error appears since the Anthropic update a couple of days ago

`Anthropic.__init__() got an unexpected keyword argument 'api_url' (type=type_error)`


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

### Reproduction

Use ChatAnthropic in any form with the latest version of Anthropic and you will encounter: "Anthropic.__init__() got an unexpected keyword argument 'api_url' (type=type_error)"


### Expected behavior

It should work if the API key is provided. You should not have to specify a URL.
Fix typo in google_places_api.py
Labels: name: auto:nit

enviroment -> environment

<!-- 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!

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: @dev2049
  - DataLoaders / VectorStores / Retrievers: @rlancemartin, @eyurtsev
  - Models / Prompts: @hwchase17, @dev2049
  - Memory: @hwchase17
  - Agents / Tools / Toolkits: @vowelparrot
  - 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
 -->
InvalidRequestError: This model's maximum context length
Labels: name: auto:bug

### System Info

langchain: 0.0.221

python:3.10.2

### Who can help?

_No response_

### Information

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

### Related Components

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

### Reproduction

from langchain.embeddings.openai import OpenAIEmbeddings
from langchain.text_splitter import CharacterTextSplitter
from langchain.vectorstores import FAISS
from langchain.document_loaders import TextLoader

from langchain.document_loaders import TextLoader

loader = TextLoader("my_file.txt")
documents = loader.load()
text_splitter = CharacterTextSplitter(chunk_size=10, chunk_overlap=0)
docs = text_splitter.split_documents(documents)

embeddings = OpenAIEmbeddings()

### Expected behavior

I‘m follow the smae code on official wbsite "https://python.langchain.com/docs/modules/data_connection/vectorstores/integrations/faiss",but replace the txt file content with another (http://novel.tingroom.com/jingdian/5370/135425.html),and the CharacterTextSplitter chunk_size set to10 ,or 100 whatever,then the error kept on raising up:InvalidRequestError: This model's maximum context length is 8191 tokens, however you requested 10137 tokens (10137 in your prompt; 0 for the completion). Please reduce your prompt; or completion length.

is this “from_documents” method has some kind of character restriction,or it just dont support Long text？