delayedkarma/langchain-issues huggingface dataset:
SQLiteCache does not cache logprobs

### System Info

Langchain version: 0.0.192, Python: 3.10

```
from langchain.cache import SQLiteCache
langchain.llm_cache = SQLiteCache(database_path='.langchain.db')
from langchain.llms import OpenAI

my_llm = OpenAI(model_name='text-davinci-003', temperature=0, max_tokens=1, logprobs=5)
result=my_llm.generate(['2+2='])
result.generations[0][0]
```

In the above, the logprobs will only be generated the first time and never again. Interestingly, the InMemoryCache does successfully persist the logprobs (and other generation_info) upon a cache hit.

@hwchase17 @yuert


### Who can help?

Any contributor.

### 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
- [ ] Async

### Reproduction

```
from langchain.cache import SQLiteCache
langchain.llm_cache = SQLiteCache(database_path='.langchain.db')
from langchain.llms import OpenAI

my_llm = OpenAI(model_name='text-davinci-003', temperature=0, max_tokens=1, logprobs=5)
result=my_llm.generate(['2+2='])
result.generations[0][0]
```

### Expected behavior

I expect the following output every time I run this

```
Generation(text='4', generation_info={'finish_reason': 'length', 'logprobs': <OpenAIObject at 0x7fbcb6ab1710> JSON: {
  "tokens": [
    "4"
  ],
  "token_logprobs": [
    -0.5794853
  ],
  "top_logprobs": [
    {
      "4": -0.5794853,
      "\n": -1.6557268,
      "5": -2.264629,
      "?": -3.518741,
      "3": -4.042759
    }
  ],
  "text_offset": [
    4
  ]
}})
```


But instead (upon the second or more times I run this), I get this:
Generation(text='4', generation_info=None)
Add Proxy to GoogleSearchAPIWrapper

### Feature request

Need to add proxy to GoogleSearchAPIWrapper()

Perhaps using this [approach](https://github.com/googleapis/google-api-python-client/issues/1078#issuecomment-718919158) and/or this [approach](https://github.com/googleapis/google-api-python-client/issues/1260#issuecomment-802728649)?

```
import httplib2
import google_auth_httplib2

http = httplib2.Http(proxy_info=httplib2.ProxyInfo(
            httplib2.socks.PROXY_TYPE_HTTP, PROXY_IP, PROXY_PORT
))

authorized_http = google_auth_httplib2.AuthorizedHttp(credentials, http=http)

service = discovery.build(http=authorized_http)
```

### Motivation

Add Proxy to GoogleSearchAPIWrapper

### Your contribution

I can write a PR but perhaps with some additional help
Add New Retriever Interface with Callbacks

Handle the new retriever events in a way that (I think) is entirely backwards compatible? Needs more testing for some of the chain changes and all.

This creates an entire new run type, however. We could also just treat this as an event within a chain run presumably (same with memory)

Adds a subclass initializer that upgrades old retriever implementations to the new schema, along with tests to ensure they work.

First commit doesn't upgrade any of our retriever implementations (to show that we can pass the tests along with additional ones testing the upgrade logic). 

Second commit upgrades the known universe of retrievers in langchain.

- [X] Add callback handling methods for retriever start/end/error (open to renaming to 'retrieval' if you want that)
- [X] Update BaseRetriever schema to support callbacks
- [X] Tests for upgrading old "v1" retrievers for backwards compatibility
- [X] Update existing retriever implementations to implement the new interface
- [X] Update calls within chains to .{a]get_relevant_documents to pass the child callback manager
- [X] Update the notebooks/docs to reflect the new interface
- [X] Test notebooks thoroughly


Not handled:
- Memory pass throughs: retrieval memory doesn't have a parent callback manager passed through the method
Using batches for Chroma update_document
Labels: name: area: vector store, name: auto:improvement

https://github.com/hwchase17/langchain/blob/2a4b32dee24c22159805f643b87eece107224951/langchain/vectorstores/chroma.py#L355-L375

Currently, the defined update_document function only takes a single document and its ID for updating. However, Chroma can update multiple documents by taking a list of IDs and documents for batch updates. 

I update the Chroma vectorstore with refreshed information from my website every 20 minutes. Updating the update_document function to perform simultaneous updates for each changed piece of information would significantly reduce the update time in such use cases. 

For my case I update a total of 8810 chunks. Updating these 8810 individual chunks using the current function takes a total of 8.5 minutes. However, if we process the inputs in batches and update them collectively, all 8810 separate chunks can be updated in just 1 minute. This significantly reduces the time it takes for users of actively used chatbots to access up-to-date information.

I also updated the integration test and the examples provided in the documentation for the new update_document function.

@hwchase17 

my twitter: [berkedilekoglu](https://twitter.com/berkedilekoglu)
Move schema to directory

As @nfcampos [pointed out](https://github.com/hwchase17/langchain/pull/5918#discussion_r1223894534), moving the schema to a directory will both let us keep it more organized and help us get around some cyclic dependencies.


Added a public API test as well.

Also realized we were importing the "~private" function `message_to_dict()` in several memory classes so made that public (along with the `message_from_dict()` function since it seems weird to only export one.  

I could alias it with the private one as well in case people were using it to make it completely backwards compatible but haven't done that yet
Update arize_callback.py

Arize released a new Generative LLM Model Type, adjusting the callback function to new logging. 

Added arize imports, please delete if not necessary. 

Specifically, this change makes sure that the prompt and response pairs from LangChain agents are logged into Arize as a Generative LLM model, instead of our previous categorical model. In order to do this, the callback functions collects the necessary data and passes the data into Arize using Python Pandas SDK. 

Arize library, specifically pandas.logger is an additional dependency. 

Notebook For Test: https://docs.arize.com/arize/resources/integrations/langchain

#### Who can review?

Tag maintainers/contributors who might be interested:


  @hwchase17 - project lead

  Tracing / Callbacks
  - @agola11
DOC: Documented example doesn't work

### Issue with current documentation:

This is for the documentation page:
   https://python.langchain.com/en/latest/modules/agents/agents/examples/structured_chat.html
This does not work in Jupyter or if you download it to a .py file and run it.  You do get 2 different errors though.
When you run this in Jupyter you get this error:

```
---------------------------------------------------------------------------
ConfigError                               Traceback (most recent call last)
Cell In[29], line 3
      1 async_browser = create_async_playwright_browser()
      2 # sync_browser = None # create_sync_playwright_browser()
----> 3 browser_toolkit = PlayWrightBrowserToolkit.from_browser(async_browser=async_browser)
      4 tools = browser_toolkit.get_tools()

File ~/Google Drive/PycharmProjectsLocal/pythonProject2/venv/lib/python3.8/site-packages/langchain/agents/agent_toolkits/playwright/toolkit.py:83, in PlayWrightBrowserToolkit.from_browser(cls, sync_browser, async_browser)
     81 # This is to raise a better error than the forward ref ones Pydantic would have
     82 lazy_import_playwright_browsers()
---> 83 return cls(sync_browser=sync_browser, async_browser=async_browser)

File ~/Google Drive/PycharmProjectsLocal/pythonProject2/venv/lib/python3.8/site-packages/pydantic/main.py:339, in pydantic.main.BaseModel.__init__()

File ~/Google Drive/PycharmProjectsLocal/pythonProject2/venv/lib/python3.8/site-packages/pydantic/main.py:1076, in pydantic.main.validate_model()

File ~/Google Drive/PycharmProjectsLocal/pythonProject2/venv/lib/python3.8/site-packages/pydantic/fields.py:860, in pydantic.fields.ModelField.validate()

ConfigError: field "sync_browser" not yet prepared so type is still a ForwardRef, you might need to call PlayWrightBrowserToolkit.update_forward_refs().
```

When you run it as a .py file you get this error:
```
Connected to pydev debugger (build 231.9011.38)
Traceback (most recent call last):
  File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/pydevd.py", line 1496, in _exec
    pydev_imports.execfile(file, globals, locals)  # execute the script
  File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "/Users/greggwcasey/Google Drive/PycharmProjectsLocal/pythonProject2/structured_chat.py", line 76
    response = await agent_chain.arun(input="Hi I'm Erica.")
               ^
SyntaxError: 'await' outside function
python-BaseException
```

### Idea or request for content:

I would like to have a working example that I could download and run on my Jupyter server or Colab and it work as-is.
feat: Add `UnstructuredXMLLoader` for `.xml` files
Labels: name: lgtm

# Unstructured XML Loader
Adds an `UnstructuredXMLLoader` class for .xml files. Works with unstructured>=0.6.7. A plain text representation of the text with the XML tags will be available under the `page_content` attribute in the doc.

### Testing
```python
from langchain.document_loaders import UnstructuredXMLLoader

loader = UnstructuredXMLLoader(
    "example_data/factbook.xml",
)
docs = loader.load()
```


## Who can review?

@hwchase17 
@eyurtsev
Clarifai integration
Labels: name: enhancement, name: llms, name: area: vector store

<!--
Thank you for contributing to LangChain! Your PR will appear in our release under the title you set. Please make sure it highlights your valuable contribution.

Replace this with a description of the change, the issue it fixes (if applicable), and relevant context. List any dependencies required for this change.

After you're done, someone will review your PR. They may suggest improvements. If no one reviews your PR within a few days, feel free to @-mention the same people again, as notifications can get lost.

Finally, we'd love to show appreciation for your contribution - if you'd like us to shout you out on Twitter, please also include your handle!
-->

<!-- Remove if not applicable -->

# Changes
This PR adds [Clarifai](https://www.clarifai.com/) integration to Langchain. Clarifai is an end-to-end AI Platform. Clarifai offers user the ability to use many types of LLM (OpenAI, cohere, ect and other open source models). As well, a clarifai app can be treated as a vector database to upload and retrieve data. The integrations includes:
- Clarifai LLM integration: Clarifai supports many types of language model that users can utilize for their application
- Clarifai VectorDB: A Clarifai application can hold data and embeddings. You can run semantic search with the embeddings

#### Before submitting
- [x] Added integration test for LLM 
- [x] Added integration test for VectorDB 
- [x] Added notebook for LLM 
- [x] Added notebook for VectorDB 


#### Who can review?
  - @hwchase17
  - @agola11
  - @dev2049
BadRequestError: BadRequestError(400, 'search_phase_execution_exception', 'runtime error') using ElasticVectorSearch

### System Info

langchain version = '0.0.191'
elasticsearch version='(8, 8, 0)'

### Who can help?

@hwchase17 @eyurtsev 

### 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 am trying ElasticVectorSearchon langchain with my Azure elastic instance and I am getting `BadRequestError: BadRequestError(400, 'search_phase_execution_exception', 'runtime error')`

```
from langchain import ElasticVectorSearch
from langchain.embeddings import OpenAIEmbeddings

embedding = OpenAIEmbeddings()

elastic_host = "hostid.westeurope.azure.elastic-cloud.com"  
elasticsearch_url = f"https://user:password-elastic@{elastic_host}:9243"
elastic_vector_search = ElasticVectorSearch(
    elasticsearch_url=elasticsearch_url,
    index_name="test_langchain",
    embedding=embedding
)

```
`doc = elastic_vector_search.similarity_search("simple query")`

The response is :
`BadRequestError: BadRequestError(400, 'search_phase_execution_exception', 'runtime error')`

### Expected behavior

It should return a list of document that match the query from elastic search
Ability to pass in ids for opensearch docs

### Feature request

There is no way to update existing vectors in the opensearch implementation for example if some existing text was changed by passing in custom ids.

https://github.com/hwchase17/langchain/blob/master/langchain/vectorstores/opensearch_vector_search.py#L95

### Motivation

Pinecone implementation has this basic functionality: 
https://github.com/hwchase17/langchain/blob/master/langchain/vectorstores/pinecone.py#L85

### Your contribution

I can try to make a PR to mirror the pincone implementation but it would be pretty naive.
Update to Vectara integration
Labels: name: lgtm

This PR updates the Vectara integration (@hwchase17 ):
* Adds reuse of requests.session to imrpove efficiency and speed.
* Utilizes Vectara's low-level API (instead of standard API) to better match user's specific chunking with LangChain
* Now add_texts puts all the texts into a single Vectara document so indexing is much faster.
* updated variables names from alpha to lambda_val (to be consistent with Vectara docs) and added n_context_sentence so it's available to use if needed.
* Updates to documentation and tests
enhancment: optional file loader in `GoogleDriveLoader`

### Summary

Gives users the ability to specify a `file_loader_cls` for processing files in Google Drive that are not Google Documents or Google Sheets.

Fixes #5791. See also [this Twitter thread](https://twitter.com/klaudioz/status/1666124861482184708?s=46&t=UImYT1AvX587tYTQ2i1sIQ) where a user requested this capability.

### Testing

For individual files (use a file id from your own GDrive):

```python
from langchain.document_loaders import GoogleDriveLoader
from langchain.document_loaders import UnstructuredFileIOLoader

file_id="1x9WBtFPWMEAdjcJzPScRsjpjQvpSo_kz"
loader = GoogleDriveLoader(
    file_ids=[file_id],
    file_loader_cls=UnstructuredFileIOLoader,
    file_loader_kwargs={"mode": "elements"}
)
loader.load()
```

For a folder:

```python
from langchain.document_loaders import GoogleDriveLoader
from langchain.document_loaders import UnstructuredFileIOLoader

folder_id="1asMOHY1BqBS84JcRbOag5LOJac74gpmD"
loader = GoogleDriveLoader(
    folder_id=folder_id,
    file_loader_cls=UnstructuredFileIOLoader,
    file_loader_kwargs={"mode": "elements"}
)
loader.load()
```

#### Who can review?

@hwchase17
@eyurtsev
Expose full params in Qdrant

# Expose full params in Qdrant

There were many questions regarding supporting some additional parameters in Qdrant integration. Qdrant supports many vector search optimizations that were impossible to use directly in Qdrant before. That includes:

1. Possibility to manipulate collection params while using `Qdrant.from_texts`. The PR allows setting things such as quantization, HNWS config, optimizers config, etc. That makes it consistent with raw `QdrantClient`.
2. Extended options while searching. It includes HNSW options, exact search, score threshold filtering, and read consistency in distributed mode.

After merging that PR, #4858 might also be closed.

## Who can review?

VectorStores / Retrievers / Memory

@dev2049 @hwchase17
VectorStore add embedded texts interface

### Feature request

Add a way to pass pre-embedded texts into the VectorStore interface.

Options:
- Standardize the add_embeddings function that has been added to some of the implementations. e.g.
```
    def add_embeddings(
        self,
        texts: List[str],
        embeddings: List[List[float]],
        metadatas: Optional[List[dict]] = None,
        **kwargs: Any,
    ) -> List[str]:
```
- Add embeddings kwarg to the add_texts interface
```
    def add_texts(
        self,
        texts: Iterable[str],
        metadatas: Optional[List[dict]] = None,
        embeddings: Optional[List[List[float]]] = None,
        **kwargs: Any,
    ) -> List[str]:
```

First option is nice in that it leaves each function with a very distinct role, but has added overhead for implementing the interface. Results in very similar code between add_texts and add_embeddings and/or a third private method to handle the actual add operation.

Second option should be pretty straightforward to add to all the implementations, but adds some clutter to the add_texts interface. No too bad IMO as it would be handled almost the same as metadatas.

### Motivation

Embedding a large body of text (e.g. pubmed) takes a long time, and it is too restrictive to rely on each VectorStore implementation calling embedding functions in the most optimal way every use case. By having a defined way to pass in embeddings directly the interface becomes much more flexible.

For example I've been using huggingface's Datasets.map for processing texts, running embeddings on multiple gpus, etc. Would like to be able to save the final embedded dataset, and then insert into the vector store.

### Your contribution

Happy to help work on it. I know there's quite a few vector store implementations that would have to be updated for this.
Not able to set k top documents in Chroma DB based Retriever

### System Info

I7 32 GBRAM , ASUS dynabook protege 

### Who can help?

@hwchase17 @agola11 @vow

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

```
db = Chroma.from_texts(chunks, embeddings, persist_directory='db', client_settings=CHROMA_SETTINGS)
chat_llm = ChatOpenAI(model_name = 'gpt-3.5-turbo',
                          callbacks=callbacks, 
                          verbose=True, 
                          temperature=0,
                          streaming = True
                         )
    
    question_generator = LLMChain(llm=chat_llm, prompt=CONDENSE_QUESTION_PROMPT)
    prompt = load_prompt(model_name='gpt')
    doc_chain = load_qa_chain(llm=chat_llm,chain_type="stuff",prompt=prompt) 
    chain = ConversationalRetrievalChain(retriever=vectorstore.as_retriever(search_kwargs={"k": 2}), 
                                     question_generator=question_generator, 
                                     combine_docs_chain=doc_chain, 
                                     memory=memory, 
                                     return_source_documents=True, 
                                     get_chat_history=lambda h :h)
```

### Expected behavior

I wish to change the `search_kwargs` more specifically `top k` relevant documents which are retrieved but I am not able to change it ! it is repeatedly providing the default 4 documents. I have tried all the required method. 

I am using Chroma DB as retriever on bunch of pdfs.
Improvement: Do not run map on a single document in MapReduceDocumentsChain
Labels: name: auto:improvement

If a single document is provided, the mapping step in `acombine_docs()` will be skipped. Before, the document was summarized using the map_prompt and then again using the combine_prompt. Assumption is, that this single document fits into the context window.

Replaced self._process_results() with an async version and call with asyncio.run() from the sync methods

Fixes #1937 

#### Who can review?
@hwchase17 

Tag maintainers/contributors who might be interested:
@agola11
Update dataframe.py
Labels: name: area: doc loader, name: auto:improvement

The original DataFrameLoader class has a limitation that only allows it to load one column out of all other columns in a dataframe. To overcome this limitation, a new class called DataFrameContentLoader has been implemented.

The DataFrameContentLoader class allows for the loading of all the columns in a dataframe by setting the index as the metadata, dropping the index from the iteration variable row, and then converting the row to a dictionary. Since the Document class does not expect a dictionary, the text is converted to a string that looks like a JSON object.

This implementation allows the DataFrameContentLoader to load all the contents of the dataframe rather than just one column. This is particularly useful when dealing with datasets that have multiple columns of relevant information.

<!--
Thank you for contributing to LangChain! Your PR will appear in our release under the title you set. Please make sure it highlights your valuable contribution.

Replace this with a description of the change, the issue it fixes (if applicable), and relevant context. List any dependencies required for this change.

After you're done, someone will review your PR. They may suggest improvements. If no one reviews your PR within a few days, feel free to @-mention the same people again, as notifications can get lost.

Finally, we'd love to show appreciation for your contribution - if you'd like us to shout you out on Twitter, please also include your handle!
-->

<!-- Remove if not applicable -->

Fixes # (issue)

#### Before submitting

<!-- If you're adding a new integration, please include:

1. a test for the integration - favor unit tests that does not rely on network access.
2. an example notebook showing its use


See contribution guidelines for more information on how to write tests, lint
etc:

https://github.com/hwchase17/langchain/blob/master/.github/CONTRIBUTING.md
-->

#### Who can review?

Tag maintainers/contributors who might be interested:

<!-- For a quicker response, figure out the right person to tag with @

  @hwchase17 - project lead

  Tracing / Callbacks
  - @agola11

  Async
  - @agola11

  DataLoaders
  - @eyurtsev

  Models
  - @hwchase17
  - @agola11

  Agents / Tools / Toolkits
  - @vowelparrot

  VectorStores / Retrievers / Memory
  - @dev2049

 -->
fix: use model token limit not tokenizer ditto
Labels: name: lgtm

This fixes a token limit bug in the SentenceTransformersTokenTextSplitter. Before the token limit was taken from tokenizer used by the model. However, for some models the token limit of the tokenizer (from `AutoTokenizer.from_pretrained`) does not equal the token limit of the model. This was a false assumption. Therefore, the token limit of the text splitter is now taken from the sentence transformers model token limit.

Twitter: @plasmajens

#### Before submitting

#### Who can review?

@hwchase17 and/or @dev2049