delayedkarma/langchain-issues huggingface dataset:
Issue: Json Agent tool fails when dict key is surrounded by single quotes

### Issue you'd like to raise.

The Json Agent tools (json_spec_list_keys, json_spec_get_value) fails when dict key of Action Input is surrounded by single quotes.
It only accepts double quotes. Here is a simple example.

```python
import pathlib
from langchain.tools.json.tool import JsonSpec

# [test.json]
#
# {
#   "name": "Andrew Lee",
#   "number": 1234
# }
json_spec = JsonSpec.from_file(pathlib.Path("test.json"))

print(json_spec.keys("data"))  #  => ['name', 'number']
print(json_spec.value('data["name"]')) # => Andrew Lee
print(json_spec.value("data['name']")) # => KeyError("'name'")
```

To make matters worse, the json_spec_list_keys returns keys with **single quote** at Observation.
So the LLM follow it to Action input and endless error happens like below.
 
 ```
Action: json_spec_list_keys
Action Input: data
Observation: ['name', 'number']
Thought: I should look at the values associated with the "name" key
Action: json_spec_get_value
Action Input: "data['name']"
Observation: KeyError("'name'")
```

### Suggestion:

The Json Agent tools (json_spec_list_keys, json_spec_get_value)  should accept both single/double quotes for dict key like general python dict access.
cohere retries
Labels: name: lgtm

…719)

A minor update to retry Cohore API call in case of errors using tenacity as it is done for OpenAI LLMs.

#### Who can review?

@hwchase17, @agola11 

<!-- 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

 -->

<!--
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

 -->
DOC: PrompTemplate format with docs

### Issue with current documentation:

Hi, how can I see what my final prompt looks like when retrieving docs? For example, I'm not quite sure how this will end up looking:

```python
prompt_template = """Answer based on context:\n\n{context}\n\n{question}"""

PROMPT = PromptTemplate(template=prompt_template, input_variables=["context", "question"])

qa = RetrievalQA.from_chain_type(
  llm=sm_llm,
  chain_type="stuff",
  retriever=docsearch.as_retriever(),
  chain_type_kwargs={"prompt": PROMPT},
)

result = qa.run(question)
```

### Idea or request for content:

_No response_
Batching added for ChromaDB Similarity Search
Labels: name: area: vector store, name: auto:improvement

ChromaDB supports batching queries for efficient searching. Currently, the APIs used for OpenAI also support batching, so I have added batching functions for OpenAI embeddings. However, the batching implementation may vary depending on the device or API used for HuggingFace, so I haven't made any additions for that. Therefore, the functions check the embedding being used.

**_Current Situation:_**
Since there is no batching, each query is sent and processed individually.

**_Test Case:_**
I have a query set consisting of 1500 questions. In the current situation, when I retrieve the answers without batching, it takes 8.5 minutes to process all 1500 questions.

**_With Batching:_**
ChromaDB already has a query function that supports batching. Utilizing that, I have added `similarity_search_by_batch` and `similarity_search_with_score_by_batch` functions in addition to `similarity_search` and `similarity_search_with_score` functions. Since the output types of the functions will change, I didn't want to write them within the same function. If you want, we can also update it that way.

**_Test Case:_**

**_After Implementing Batching:_**

when I retrieve the answers with a batch size of 256, all 1500 questions are processed in 12 seconds. When using a batch size of 512, the answers are returned in 6 seconds.

_It is also important for decreasing request number for OpenAI API._ 

Additionally, I updated the `_results_to_docs_and_scores` function to `_results_to_docs_and_scores_for_batches`. Now the function works appropriately for batching and returns the results. Since the returned value has changed from `List[Tuple[Document, float]]` to `List[List[Tuple[Document, float]]],` I have written a separate function for handling this conversion.

my twitter: [berkedilekoglu](https://twitter.com/berkedilekoglu)


_**TEST AND DOCUMENTS**_

I think it will be necessary to add test cases for these functions, but I would greatly appreciate your help since I haven't written tests before :)

If you're okay with these changes, I can add the necessary examples to the documentation!

Thank you very much!
Berke

  VectorStores / Retrievers / Memory
  - @dev2049, @hwchase17
Removes unnecessary backslash escaping for backticks in python
Labels: name: lgtm

Fixed python deprecation warning:
    DeprecationWarning: invalid escape sequence '`'
    
   backticks (`) do not have special meaning in python strings and should not be escaped. 

-- @spazm on twitter

### Who can review:

@nfcampos ported this change from javascript, @hwchase17 wrote the original STRUCTURED_FORMAT_INSTRUCTIONS,
Add class attribute "return_generated_question" to class "BaseConversationalRetrievalChain"
Labels: name: lgtm

<!--
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!
-->

Adding a class attribute "return_generated_question" to class "BaseConversationalRetrievalChain". If set to `True`, the chain's output has a key "generated_question" with the question generated by the sub-chain `question_generator` as the value. This way the generated question can be logged.

<!-- 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?

<!-- 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

 -->
@dev2049 @vowelparrot
Pinecone.from_documents() does not create the index if it does not exist

### System Info

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

### Reproduction

docsearch = Pinecone.from_documents(chunks, embeddings, index_name=index_name)
calls from_text which returns
ValueError: No active indexes found in your Pinecone project, are you sure you're using the right API key and environment?
if the index does not exist.

``
if index_name in indexes:
            index = pinecone.Index(index_name)
        elif len(indexes) == 0:
            raise ValueError(
                "No active indexes found in your Pinecone project, "
                "are you sure you're using the right API key and environment?"
            )
``

### Expected behavior

The method should create the index if it does not exist.
This is the expected behavior from the documentation and the official examples.

Creating a new index if it does not exist is the only recommended behavior as it implies that the dimension of the index is always consistent with the dimension of the embedding model used.

Thanks

Best regards

Jerome
base implementation for azureml foundational model

<!--
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

 -->
json parser for when 3 backtiks are missing
Labels: name: lgtm

Fixes #3455 and #2276.

The parse_json_markdown function expects a JSON string within triple backticks.

However, even though it's instructed this way, LLM's responses sometimes come with fewer that 3 backticks (as also described in the issue 3455.

You can try using this string as input to test:

json_string = '\n\nRESPONSE\n--------------------\n```json\n{\n    "action": "Current Search",\n    "action_input": "Atividades de lazer em Recife"\n}\n``'


#### Who can review?

Tag maintainers/contributors who might be interested:
@vowelparrot
Addresses GPT4All wrapper model_type attribute issues  #5720.

Fixes #5720.

A more in-depth discussion is in my comment here: https://github.com/hwchase17/langchain/issues/5720#issuecomment-1577047018

In a nutshell, there has been a subtle change in the latest version of GPT4Alls Python bindings. The change I submitted yesterday is compatible with this version, however, this version is as of yet unreleased and thus the code change breaks Langchain's wrapper under the currently released version of GPT4All.

This pull request proposes a backwards-compatible solution.
Zep Hybrid Search
Labels: name: lgtm

Zep now supports persisting custom metadata with messages and hybrid search across both message embeddings and structured metadata. This PR implements custom metadata and enhancements to the `ZepChatMessageHistory` and `ZepRetriever` classes to implement this support.

Tag maintainers/contributors who might be interested:

  VectorStores / Retrievers / Memory
  - @dev2049
DOC: SageMaker JumpStart Embeddings

### Issue with current documentation:

I saw in a recent notebook demo that a custom `SagemakerEndpointEmbeddingsJumpStart` class was needed to deploy a SageMaker JumpStart text embedding model. I couldn't find any langchain docs for this.

```python
from langchain.embeddings.sagemaker_endpoint import EmbeddingsContentHandler

class SagemakerEndpointEmbeddingsJumpStart(SagemakerEndpointEmbeddings):
    def embed_documents(self, texts: List[str], chunk_size: int = 5) -> List[List[float]]:
        """Compute doc embeddings using a SageMaker Inference Endpoint.

        Args:
            texts: The list of texts to embed.
            chunk_size: The chunk size defines how many input texts will
                be grouped together as request. If None, will use the
                chunk size specified by the class.

        Returns:
            List of embeddings, one for each text.
        """
        results = []
        _chunk_size = len(texts) if chunk_size > len(texts) else chunk_size

        for i in range(0, len(texts), _chunk_size):
            #print(f"input:", texts[i : i + _chunk_size])
            response = self._embedding_func(texts[i : i + _chunk_size])
            results.extend(response)
        return results


class ContentHandler(EmbeddingsContentHandler):
    content_type = "application/json"
    accepts = "application/json"

    def transform_input(self, prompt: str, model_kwargs={}) -> bytes:
        input_str = json.dumps({"text_inputs": prompt, **model_kwargs})
        return input_str.encode("utf-8")

    def transform_output(self, output: bytes) -> str:
        response_json = json.loads(output.read().decode("utf-8"))
        embeddings = response_json["embedding"]
        return embeddings


content_handler = ContentHandler()

embeddings = SagemakerEndpointEmbeddingsJumpStart(
    endpoint_name=_MODEL_CONFIG_["huggingface-textembedding-gpt-j-6b"]["endpoint_name"],
    region_name=aws_region,
    content_handler=content_handler,
)
```


### Idea or request for content:

_No response_
Issue: TypeError: issubclass() arg 1 must be a class

### Issue you'd like to raise.

Getting the following error

TypeError: issubclass() arg 1 must be a class

when i execute:

from langchain.embeddings import HuggingFaceEmbeddings
#from transformers import pipeline

#Download model from Hugging face
model_name = "sentence-transformers/all-mpnet-base-v2"
hf_embed = HuggingFaceEmbeddings(model_name=model_name)



### Suggestion:

_No response_
AttributeError: 'GPT4All' object has no attribute 'model_type'

### System Info

run on docker image with continuumio/miniconda3 on linux
langchain-0.0.190 installed

### 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

Follow the steps here: https://python.langchain.com/en/latest/modules/models/llms/integrations/gpt4all.html

```
%pip install gpt4all > /dev/null
from langchain import PromptTemplate, LLMChain
from langchain.llms import GPT4All
from langchain.callbacks.streaming_stdout import StreamingStdOutCallbackHandler

template = """Question: {question}

Answer: Let's think step by step."""

prompt = PromptTemplate(template=template, input_variables=["question"])

local_path = './models/ggml-gpt4all-l13b-snoozy.bin'  # replace with your desired local file path

import requests

from pathlib import Path
from tqdm import tqdm

Path(local_path).parent.mkdir(parents=True, exist_ok=True)

# Example model. Check https://github.com/nomic-ai/gpt4all for the latest models.
url = 'http://gpt4all.io/models/ggml-gpt4all-l13b-snoozy.bin'

# send a GET request to the URL to download the file. Stream since it's large
response = requests.get(url, stream=True)

# open the file in binary mode and write the contents of the response to it in chunks
# This is a large file, so be prepared to wait.
with open(local_path, 'wb') as f:
    for chunk in tqdm(response.iter_content(chunk_size=8192)):
        if chunk:
            f.write(chunk)

# Callbacks support token-wise streaming
callbacks = [StreamingStdOutCallbackHandler()]
# Verbose is required to pass to the callback manager
llm = GPT4All(model=local_path, callbacks=callbacks, verbose=True)
```



### Expected behavior

The expected behavior: code returns a GPT4All object.

The following error was produced:
```
AttributeError                            Traceback (most recent call last)
Cell In[9], line 4
      2 callbacks = [StreamingStdOutCallbackHandler()]
      3 # Verbose is required to pass to the callback manager
----> 4 llm = GPT4All(model=local_path, callbacks=callbacks, verbose=True)

File /opt/conda/lib/python3.10/site-packages/pydantic/main.py:339, in pydantic.main.BaseModel.__init__()

File /opt/conda/lib/python3.10/site-packages/pydantic/main.py:1102, in pydantic.main.validate_model()

File /opt/conda/lib/python3.10/site-packages/langchain/llms/gpt4all.py:156, in GPT4All.validate_environment(cls, values)
    153 if values["n_threads"] is not None:
    154     # set n_threads
    155     values["client"].model.set_thread_count(values["n_threads"])
--> 156 values["backend"] = values["client"].model_type
    158 return values

AttributeError: 'GPT4All' object has no attribute 'model_type'
```
Add Hologres data warehouse as vectorstore
Labels: name: enhancement, name: lgtm, name: area: vector store

Hi,

This PR adds a new vector store: [Hologres](https://www.alibabacloud.com/help/en/hologres/latest/introduction)

Hologres is a product of the Alibaba Cloud Computing platform. It's a fast cloud-native data warehouse that also supports high-performance vector searching.
The example use case of Hologres is already accepted by openai-cookbook. We are actively integrating our product with outstanding open-source works and we believe langchain is a great work that has a bright future. We would appreciate it if this PR can be reviewed and accepted.

We followed the contribution guidelines, and added unit tests and a notebook example.
The code has passed the format and lint checks.


#### 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


---
Best,
Changgeng
Developer of Hologres
Issue: Correctness of generated SQL queries

### Issue you'd like to raise.

I have a huge database hosted in BigQuery. The recommended approach to querying this via natural language is using agents. However, this diminishes the control I have over the intermediate steps, and that leads to many problems.
- The generated query isn't correct, and this cannot be reinforced at any intermediate step
- Clauses like "ORDER BY" brings _NULL_ to the top, and no amount of prompt engineering can retrieve the top non-null value

Are there any workarounds for this? Or is there any other approach recommended for handling databases of this scale?

### Suggestion:

_No response_
FAISS load_local() file path issue. 

### System Info

Langchain Version : [0.0.190]
Python Version : 3.10.7
OS : Windows 10

### Who can help?

@eyurtsev @hwchase17 


### Information

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

### Related Components

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

### Reproduction

Error: RuntimeError: Error in __cdecl faiss::FileIOReader::FileIOReader(const char *) at D:\a\faiss-wheels\faiss-wheels\faiss\faiss\impl\io.cpp:68: Error: 'f' failed: could not open **D:\Question Answer Generative AI\Langchain\index_files\ThinkPalm☺\en\index.faiss** for reading: Invalid argument

Try creating a file path :  D:\Question Answer Generative AI\Langchain\index_files\ThinkPalm\1\en 
mainly some folder name with just a number, then try to load that file path using faiss.load_local(). The path created after passing string path to Path(path) class is causing some issue. 

### Expected behavior

Issue: The actual file path is : D:\Question Answer Generative AI\Langchain\index_files\ThinkPalm\1\en 
File Path created by PurePath : *D:\Question Answer Generative AI\Langchain\index_files\ThinkPalm@\en\index.faiss
postprocessors append - Langchain and Nemoguardrails

### Issue you'd like to raise.

I am trying to generate a chain from langchain and append it to the configuration within nemoguard rails.  I am getting error message LLMChain' object has no attribute 'postprocessors

I am on Langchain version 0.0.167 and nemoguardrails 0.2.0 . Nemoguard rails  0.2.0 is compatible only with the langchain version 0.0.167 and i guess postprocessor is on the latest langchain version 

Can you please check on this and provide a solution

rails = LLMRails(llm=llm, config=rails_config)
title_chain.postprocessors.append(rails)
script_chain.postprocessors.append(rails)

### Suggestion:

_No response_