delayedkarma/langchain-issues huggingface dataset:
support other metrics in faiss except Euclidean distance

### Feature request

support other metrics in faiss except Euclidean distance

### Motivation

the code in faiss had only supprt euclidean distance, like code below 
index = faiss.IndexFlatL2(len(embeddings[0]))
```python
   @classmethod
    def __from(
        cls,
        texts: List[str],
        embeddings: List[List[float]],
        embedding: Embeddings,
        metadatas: Optional[List[dict]] = None,
        ids: Optional[List[str]] = None,
        normalize_L2: bool = False,
        **kwargs: Any,
    ) -> FAISS:
        faiss = dependable_faiss_import()
        index = faiss.IndexFlatL2(len(embeddings[0]))
        vector = np.array(embeddings, dtype=np.float32)
        if normalize_L2:
            faiss.normalize_L2(vector)
        index.add(vector)
        documents = []
        if ids is None:
            ids = [str(uuid.uuid4()) for _ in texts]
        for i, text in enumerate(texts):
            metadata = metadatas[i] if metadatas else {}
            documents.append(Document(page_content=text, metadata=metadata))
        index_to_id = dict(enumerate(ids))
        docstore = InMemoryDocstore(dict(zip(index_to_id.values(), documents)))
        return cls(
            embedding.embed_query,
            index,
            docstore,
            index_to_id,
            normalize_L2=normalize_L2,
            **kwargs,
        )
```

### Your contribution

I want to change the code and let it supoort more metrics
load_summarize_chain with Pydantic format instructions return cut at the end output (as it stops writing in the middle of the sentence)

### System Info

langchain==0.0.201
Python 3.10.8


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

### Reproduction

I use load_summarize_chain with my own map and reduce prompts to process video transcript and receive chapters of the video and json format. In the intermediate steps there is no problem - all documents are processed well as I can see in created chapters. However after reduce last few chapters are missed and cut off like it suddenly stops writing output.

- The bug often appears when processing long videos: 50 minutes and longer (however rarely they processed without problems). 
- Without output parser (format instructions) it often don't cut off, but can have problems with format.
- Number of tokens after map in my example fewer than 3000 (e.g. 2462, 2704, 2704) so collapse prompt doesn't help.
- Number of tokens of output after reduce is not that big (e.g. 1057, 755). I have examples of bigger results from smaller videos that worked well.

So it is not that output or input for reduce are too big for prompt, because no error about too many values occurs. 
I could not find any other possible reasons for such behavior.

Here the code example:
```
output_parser = PydanticOutputParser(pydantic_object=Chapters)
format_instructions = output_parser.get_format_instructions()
# Unload dict
map_prompt = prompt_config["map_prompt"]
reduce_prompt = prompt_config["reduce_prompt"]
# Initialize templates
map_temp = PromptTemplate(input_variables=["text"], template=map_prompt, partial_variables={"format_instructions": format_instructions})
reduce_temp = PromptTemplate(input_variables=["text"], template=reduce_prompt, partial_variables={"format_instructions": format_instructions})

chain_mapreduce = load_summarize_chain(
        llm,
        chain_type="map_reduce",
        return_intermediate_steps=True,
        map_prompt=map_temp,
        combine_prompt=reduce_temp,
 )
res = chain_mapreduce({"input_documents": docs}, return_only_outputs=True)
```

### Expected behavior

I expect the well formed json output without information loss
feat: add similarity_search_by_vector_with_relevance_scores to Pineco…
Labels: name: area: vector store, name: auto:improvement

Following on from #6056, the underlying langchain VectorStore class doesn't have a method called 
`similarity_search_by_vector_with_relevance_scores` to allow getting a handle on the relevance scores when querying by vector, similarly to how it is done with `similarity_search` and `similarity_search_with_relevance_scores`.

Since adding such an abstract method to the base `VectorStore` class would require implementing it for all `VectorStores`, I haven't done that here. As a baby step towards the larger task, I have just added `similarity_search_by_vector_with_relevance_scores` to the `Pinecone` vector store.

#### Who can review?

Tag maintainers/contributors who might be interested:

VectorStores / Retrievers / Memory
  - @dev2049
CohereEmbeddings do not work in Context class

### System Info

==versions==
python 3.9
langchain 0.0.186
pydantic 1.10.8
windows 11

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

==run source===
from langchain.embeddings import CohereEmbeddings
from langchain.chains.base import Chain

class Neo4jContextTool(Chain):
    """Chain for context search with cohere embedding"""

    embeddings = CohereEmbeddings()

==traceback==
Traceback (most recent call last):
  File "\Python39\lib\code.py", line 90, in runcode
    exec(code, self.locals)
  File "<input>", line 5, in <module>
  File "pydantic\main.py", line 221, in pydantic.main.ModelMetaclass.__new__
  File "pydantic\fields.py", line 506, in pydantic.fields.ModelField.infer
  File "pydantic\fields.py", line 436, in pydantic.fields.ModelField.__init__
  File "pydantic\fields.py", line 546, in pydantic.fields.ModelField.prepare
  File "pydantic\fields.py", line 570, in pydantic.fields.ModelField._set_default_and_type
  File "pydantic\fields.py", line 439, in pydantic.fields.ModelField.get_default
  File "pydantic\utils.py", line 693, in pydantic.utils.smart_deepcopy
  File "\Python39\lib\copy.py", line 172, in deepcopy
    y = _reconstruct(x, memo, *rv)
  File "\Python39\lib\copy.py", line 270, in _reconstruct
    state = deepcopy(state, memo)
  File "\Python39\lib\copy.py", line 146, in deepcopy
    y = copier(x, memo)
  File "\Python39\lib\copy.py", line 230, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "\Python39\lib\copy.py", line 146, in deepcopy
    y = copier(x, memo)
  File "\Python39\lib\copy.py", line 230, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "\Python39\lib\copy.py", line 172, in deepcopy
    y = _reconstruct(x, memo, *rv)
  File "\Python39\lib\copy.py", line 270, in _reconstruct
    state = deepcopy(state, memo)
  File "\Python39\lib\copy.py", line 146, in deepcopy
    y = copier(x, memo)
  File "\Python39\lib\copy.py", line 230, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "\Python39\lib\copy.py", line 172, in deepcopy
    y = _reconstruct(x, memo, *rv)
  File "\Python39\lib\copy.py", line 270, in _reconstruct
    state = deepcopy(state, memo)
  File "\Python39\lib\copy.py", line 146, in deepcopy
    y = copier(x, memo)
  File "\Python39\lib\copy.py", line 230, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "\Python39\lib\copy.py", line 161, in deepcopy
    rv = reductor(4)
TypeError: cannot pickle '_queue.SimpleQueue' object


### Expected behavior

creating class without errors. 
same code with OpenAIEmbeddings do not have this error
LLMRequestsChain not enforcing headers when making http requests

### System Info

LangChain version 0.0.201

### Who can help?

@hwchase17 @agola

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

### Reproduction

Based on the documentation example, run the following script: 

```python
from langchain.llms import OpenAI
from langchain.chains import LLMRequestsChain, LLMChain
from langchain.prompts import PromptTemplate

template = """Here is a company website content :
    ----
    {requests_result}
    ----
    We want to learn more about a company's activity and the kind of
    clients they target. Perform an analysis and write a short summary.
"""

PROMPT = PromptTemplate(
    input_variables=["requests_result"],
    template=template,
)

chain = LLMRequestsChain(llm_chain = LLMChain(llm=OpenAI(temperature=0), prompt=PROMPT))

print(chain.requests_wrapper)

```

Gives 

```bash
python3 bug-langchain-requests.py
headers=None aiosession=None
```

### Expected behavior

Provided headers should be enforced

```bash
python3 bug-langchain-requests.py
headers={'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36'} aiosession=None
```
Fix integration tests for Faiss vector store

Fixes #5807 (issue)

#### Who can review?

Tag maintainers/contributors who might be interested: @dev2049

<!-- 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
  - @hwchase17

  VectorStores / Retrievers / Memory
  - @dev2049

 -->
Setting session name through env variable LANGCHAIN_SESSION

### System Info

Setting LANGCHAIN_SESSION through env variable gives the following error:

WARNING:root:Failed to load dev session, using empty session: list index out of range

### Who can help?

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

### Reproduction

Just setting `os.environ["LANGCHAIN_SESSION"] = "dev"` And when running LLMChain in langchain module throws the error

### Expected behavior

It should log traces in the assign session_name
refactor confluence loader to reduce http requests
Labels: name: area: doc loader, name: auto:improvement

`ConfluenceLoader` fetches the restrictions for each page in `is_public_page()` without backoff retries. This can cause the `requests.exceptions.HTTPError: Rate limit exceeded.` error.

Expand the restrictions of pages when getting page contents to reduce the http requests.

#### Who can review?

Tag maintainers/contributors who might be interested:@eyurtsev
searx_search: updated tools and doc

- Allows using the  same wrapper to create multiple tools
```python
wrapper = SearxSearchWrapper(searx_host="**")
github_tool = SearxSearchResults(name="Github",
                            wrapper=wrapper,
                            kwargs = {
                                "engines": ["github"],
                                })

arxiv_tool = SearxSearchResults(name="Arxiv",
                            wrapper=wrapper,
                            kwargs = {
                                "engines": ["arxiv"]
                                })
```

- Updated link to searx documentation

  Agents / Tools / Toolkits
  - @hwchase17
Improve error message
Labels: name: lgtm

Trying to use OpenAI models like 'text-davinci-002' or 'text-davinci-003' the agent doesn't work and the message is 'Only supported with OpenAI models.' The error message should be 'Only supported with ChatOpenAI models.'

My Twitter handle is @alonsosilva
<!--
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:
@hwchase17

<!-- 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
  - @hwchase17

  VectorStores / Retrievers / Memory
  - @dev2049

 -->
feat: Add streaming only final aiter of agent
Labels: name: enhancement, name: callbacks

<!--
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 -->

#### Add streaming only final async iterator of agent
This callback returns an async iterator and only streams the final output of an agent.

<!-- 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: @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
  - @hwchase17

  VectorStores / Retrievers / Memory
  - @dev2049

 -->
Qdrant: Add vectors to already existing collection & static vector size

Problem:
Whenever we add vectors to an existing qdrant collection that collection gets deleted and re-created from scratch.
But if we want to add vectors to an existing collection in a later stage, then it's not possible with the current implementation.

This PR solves this issue without breaking the already existing behavior. It adds the ability to add more vectors to an already existing collection via an optional flag. 

In addition to that this PR adds the ability to configure a fixed vector size , eliminating the need to make a quick single embedding just to figure out the vector size.

So this PR introduces the following two flags:

`recreate_collection = Optional[int]`

`vector_size = Optional[bool]`

How this solution works:
1. It checks if collection exists, if not, continue like before this PR (recreate collection)
2. if collection exists, and recreate_collection=False, and init_from=None then do not execute `recreate_collection()`

Before continuing I'd like to hear your feedback and thoughts which is the reason why this PR is in draft and doesn't provide the other required parts (tests, etc), yet.
Modify the pubmed api wrapper
Labels: name: needs work

Modify the pubmed api wrapper.
* 1.  Add query sorting capabilities, 
* 2. Add NCBI API function to increase the number of requests to 10 per minute
* 3. Use the History server of NCBI, break the post limit, can download tens of thousands of article infomation.

#### Who can review?

@ Harrison Chase
  @hwchase17 - project lead

  Models
  - @hwchase17
  - @agola11

  Agents / Tools / Toolkits
  - @hwchase17

  VectorStores / Retrievers / Memory
  - @dev2049
The callback module openai_info does not have the correct model name for gpt-35-turbo

The openai_info.py does not have the correct model name for Azure Open AI. The model name is gpt-35-turbo. If you pass model name as gpt-3.5-turbo, then the code will fail with error "must provide 'engine' or 'deployment_id'. And if we pass gpt-35-turbo, since it was not there in the openai_info.py, the total cost was being calculated as 0.00. This solution fixes this issue
Fixes # (issue)
Before submitting
Who can review?
Tag maintainers/contributors who might be interested:
Request to please review and merge.
@hwchase17 
@agola11
The callback module openai_info does not have the correct model name for gpt-35-turbo

The openai_info.py does not have the correct model name for Azure Open AI. The model name is gpt-35-turbo. If you pass model name as gpt-3.5-turbo, then the code will fail with error "must provide 'engine' or 'deployment_id'. And if we pass gpt-35-turbo, since it was not there in the openai_info.py, the total cost was being calculated as 0.00. This solution fixes this issue

<!-- 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:

Request to please review and merge.

@hwchase17 
@agola11
PyPDFLoader to accept bytes objects as well

### Feature request

class PyPDFLoader in [document_loaders/pdf.py](https://github.com/hwchase17/langchain/blob/master/langchain/document_loaders/pdf.py) to accept bytes object as well.

### Motivation

When a PDF file is uploaded using a REST API call, there is no specific file_path to load from. The solution can be to use file bytes instead as input parameter.

### Your contribution

I can submit a PR
I just said hi. model is in multiple rounds of conversations with himself. Why?

### System Info

![hi](https://github.com/hwchase17/langchain/assets/5000490/b22c82e7-6d78-4eb6-9c46-5d888ed1d7cf)


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

from langchain import OpenAI, ConversationChain, LLMChain, PromptTemplate
from langchain.memory import ConversationBufferWindowMemory
from langchain.callbacks.streaming_stdout import StreamingStdOutCallbackHandler

template = """
{history}
Human: {human_input}
Assistant:"""

prompt = PromptTemplate(
    input_variables=["history", "human_input"], 
    template=template
)

chatgpt_chain = LLMChain(
    llm=OpenAI(streaming=True, temperature=0), 
    prompt=prompt, 
    verbose=True, 
    memory=ConversationBufferWindowMemory(k=2),
)

output = chatgpt_chain.predict(human_input="hi")
print(output)

### Expected behavior

I just said hi. model is in multiple rounds of conversations with himself. Why?

I hope  model don't talk to myself
Allow returning the final prompts that are sent to LLMs
Labels: name: auto:improvement

#### Problem
Prompts are formatted and merged (e.g. adding `---context---\n`) before being sent to LLMs. The final prompts sent to LLMs can vary depending on the type of chains used and can be quite different from the original inputs to the chains. However, the user cannot see such differences directly, making debugging more difficult.

#### Changes
- Allow returning the final prompts as part of `LLMResult`. 
- Final prompts here are collected before being sent to specific API vendors (e.g. OpenAI). Therefore the addition to `LLMResult` not `ChatResult`.
- Final prompts are returned with the `_call()` method of `LLMChain` in `/chains/llm.py`.

#### Limitations
- This is not yet implemented on all usage of `LLMResult` (i.e. only implemented in /chat_models not /llms)
- Due to the use of `predict()` instead of `_call()` in most of the chains, final prompts will not be returned there.
- Async versions are not implemented
- **If you like the idea, I can fix the above limitations**

#### Who can review?

Tag maintainers/contributors who might be interested:
  @hwchase17
  @agola11
For AzureOpenAI() wrapper deafault model_name is text-davinci-003
Labels: name: stale

### System Info

If we do not pass the model_name in the AzureOpenAI() wrapper, it picks up text-davinci-003 as the default model which in turn makes the cost calculation of tokens incorrect. Should model_name be made mandatory parameter for AzureOpenAI()

### Who can help?

@hwchase17 
@agola11 

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

Use the AzureOpenAI() wrapper without passing model_name and then do a get_openai_callback() to get the cost

### Expected behavior

It should calculate the cost based on the model name
Iterate through filtered file types instead of all listed files
Labels: name: lgtm

# Iterate through filtered file types instead of all listed files

Fixes https://github.com/hwchase17/langchain/issues/6257

https://github.com/hwchase17/langchain/pull/4926 originally added the functionality to filter by file type, storing the filtered files in `_files`

https://github.com/hwchase17/langchain/pull/5220 removed the functionality when adding code to filter trashed files by using the `files` variables instead of the `_files` variable.

This PR simply adds the functionality back by using `_files` again.

#### Who can review?

@hwchase17 - project lead
@eyurtsev