delayedkarma/langchain-issues huggingface dataset:
JSONLoader ignores metadata processed with `metadata_func`

JSONLaoder takes a callable `metadata_func` that should supposedly allow the user to enrich the document metadata. The output of the callable however is unused and the and docs are created with the bare source/seq_num pairs.

https://github.com/hwchase17/langchain/blob/7414e9d19603c962063dd337cdcf3c3168d4b8be/langchain/document_loaders/json_loader.py#L67-L101
Deprecated web_path in favor of web_paths for WebLoader
Labels: name: lgtm

I completed this TODO and also fixed the sitemap tests and xml so it passes and uses the latest langchain website and sitemap.
        # TODO: Deprecate web_path in favor of web_paths, and remove this
        # left like this because there are a number of loaders that expect single
        # urls
        if isinstance(web_path, str):
            self.web_paths = [web_path]
        elif isinstance(web_path, List):
            self.web_paths = web_path

WebBaseLoader should also still work with everything that relies on it still. If there are more tests I need to run for the implementation, let me know.

Twitter @Elapse_ai
feat(agents): allow trimming of intermediate steps to last N

<!--
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!
-->

Added an option to trim intermediate steps to last N steps. This is especially useful for long-running agents. Users can explicitly specify N or provide a function that does custom trimming/manipulation on intermediate steps. I've mimicked the API of the `handle_parsing_errors` parameter.

<!-- Remove if not applicable -->

Fixes #6370 

#### 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

 -->
Pgvector similarity score threshold

<!--
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 #6346

#### 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: @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

 -->
typo(llamacpp.ipynb): 'condiser' -> 'consider'
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!
-->

Fixes a typo on the `llamacpp.ipynb` notebook.


#### Before submitting
Related to Model Documentation

  Models
  - @agola11


Your effort is strongly appreciated, thank you for making development with models much easier and more accessible.
DOC: Incorrect type for tags parameter in MLflow callback

### Issue with current documentation:

In the documentation the tag type is string, but in the code it's a dictionary.

The proposed fix is to change the following two lines "tags (str):" to "tags (dict):".

https://github.com/hwchase17/langchain/blob/7414e9d19603c962063dd337cdcf3c3168d4b8be/langchain/callbacks/mlflow_callback.py#L120

https://github.com/hwchase17/langchain/blob/7414e9d19603c962063dd337cdcf3c3168d4b8be/langchain/callbacks/mlflow_callback.py#L225

### Idea or request for content:

_No response_
pdf-parse.d.ts not found when using PDFLoader

### System Info

{
  "name": "server-chatgpt",
  "version": "1.0.0",
  "description": "",
  "type": "module",
  "main": "dist/app.js",
  "scripts": {
    "start": "tsc & node dist/app.js",
    "dev": "tsc -w & nodemon -x 'node dist/app.js || touch dist/app.js'",
    "dev2": "tsc -w & pm2 start dist/app.js --watch",
    "log": "pm2 log",
    "stop": "pm2 stop app",
    "lint": "eslint . --ext .ts",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "@types/cors": "^2.8.13",
    "@types/express": "^4.17.17",
    "@typescript-eslint/eslint-plugin": "^5.59.6",
    "@typescript-eslint/parser": "^5.59.6",
    "eslint": "^8.41.0",
    "nodemon": "^2.0.22",
    "pm2": "^5.3.0",
    "ts-node": "^10.9.1",
    "typescript": "^5.0.4"
  },
  "dependencies": {
    "@types/node": "^20.3.1",
    "@types/pdf-parse": "^1.1.1",
    "body-parser": "^1.20.2",
    "chatgpt": "^5.2.4",
    "chromadb": "^1.5.2",
    "cors": "^2.8.5",
    "dotenv": "^16.0.3",
    "express": "^4.18.2",
    "hnswlib-node": "^1.4.2",
    "langchain": "^0.0.95",
    "openai": "^3.2.1",
    "pdfjs-dist": "^3.7.107",
    "pg": "^8.11.0",
    "typeorm": "^0.3.16",
    "uuid": "^9.0.0"
  }
}


### Who can help?

@eyurtsev @agola11

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

### Reproduction

When "npm run dev" is executed, I get an error saying node_modules/langchain/dist/document_loaders/fs/pdf.d.ts:1:22 - error TS6053: /node_modules/langchain/src/types/pdf-parse.d.ts' not found.

/// <reference path="../../../src/types/pdf-parse.d.ts" />

This error comes when I try to import { PDFLoader } from "langchain/document_loaders/fs/pdf";

tsconfig:
{
    "compilerOptions": {
      "module": "NodeNext",
      "esModuleInterop": true,
      "target": "es6",
      "moduleResolution": "nodenext",
      "sourceMap": true,
      "outDir": "dist",
      "resolveJsonModule": true,
      "allowJs": true
    },
    "lib": ["es2015"]
  }
  

### Expected behavior

no error is expected as pdf-parse is already installed, similar issue with pdfjs-dist
DOC: Broken link to the Text Embedding Model

### Issue with current documentation:

[Text Embedding Model python Guide ](https://python.langchain.com/docs/modules/model_io/models/text_embedding.html) Seems to be broken and can't be accessed.
![issue1](https://github.com/hwchase17/langchain/assets/101401469/4af5afb4-fc3e-44e2-b8c9-2bcc5f1eeb49)
![issue2](https://github.com/hwchase17/langchain/assets/101401469/6cfdb145-3d82-4f1a-b9d0-e086782b4fa1)


### Idea or request for content:

_No response_
Fix conversational_retrieval combining with chat history affects the question and answer experience

<!--
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)
While using the ConversationalRetrievalChain, and specifically applying both condense_question_prompt and combine_docs_chain_kwargs parameters, I followed the official documentation to pass chat_history when invoking this chain. The program runs as expected, but the Q&A experience is less than optimal. I've identified two main issues:

When summarizing the question using condense_question, the response prompt generated by load_qa_chain is treated as 'Human' rather than 'AI'. Currently, I am remedying this by determining whether to pass the question to human_message or ai_message, based on whether chat_history is provided through an external interface.

Upon reviewing the code, I noticed that the answer is first generated by self.question_generator, but in reality, the desired answer initially comes from the prompt in combine_docs_chain_kwargs. However, this response is then re-fed into self.combine_docs_chain, leading to a situation of self-posed questions and self-given answers, which isn't ideal. The final answer from combine_docs_chain isn't what I'm looking for, and I see no need to go through another loop only to end up with an unsatisfactory answer. Thus, I wish to adjust the logic for obtaining the answer in the call and acall methods.

While my implementation might not be the most ideal, it considerably enhances the Q&A experience based on chat history in my project. I hope for official support on this issue and appreciate your help. Thank you!
#### 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?
@hwchase17 Please review my code and provide your guidance
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
  - @hwchase17

  VectorStores / Retrievers / Memory
  - @dev2049

 -->
Multiple completions support in ChatOpenAI

### Feature request

Multiple Completions support would enable users to receive multiple responses or variations from the model for a given prompt. This feature would provide greater flexibility and allow users to explore different possibilities or perspectives in their conversations.

Allowing users to specify the number of completions they desire, it would enhance the richness and diversity of the generated responses. Users could gain a deeper understanding of different potential outcomes or receive alternative suggestions.

Multiple Completions support would be particularly valuable in scenarios where users are seeking creative ideas, exploring different options, or generating diverse responses for analysis. It would enable users to generate a range of potential answers, facilitating more comprehensive and robust conversations.

I believe that the implementation of Multiple Completions support in ChatOpenAI would greatly enhance the user experience and provide increased utility across a wide range of applications.

Please correct me and let me know if this feature is already available. Also in this case, please let me know how to access the same.

### Motivation

I am building a framework that uses the multiple completions feature but I am not able to find this feature in ChatOpenAI.that

### Your contribution

I will try to help the community to the best of my knowledge.
Issue: <Some problems when using ChatOpenAI>

### Issue you'd like to raise.

When using ChatOpenAI, will ChatOpenAI save the conversation history? When I use the same data many times to call a service built with langchain, after a fixed number of times, a langchain.schema.OutputParserException error occurs, which seems to be The answer returned by OpenAI is incomplete. Based on my experience of using other GPT models, it tells me that this is because the dialogue history recorded by the model is too long, causing the answer and the token of the dialogue history to exceed the length of the model limit. How should I avoid this problem? , or how should I start a new conversation or clear the conversation history after the ChatOpenAI conversation ends.

### Suggestion:

_No response_
Add ability to add extra fields to AzureSearch VectorStore when adding documents

Fixes #6134 

This PR adds a feature to the ACS Vectorstore for adding extra fields beyond the required fields when adding documents into an Azure Cognitive Search Vectorstore.  By adding these extra fields , when later querying the vectorstore, the search engine's filtering capabilities can be used to narrow the number of records when doing the vector comparison.

The usage of this feature is:


```
extra_fields = {"extra_fields": {"important_field_1": 123, "important_field_2": 456}}

documents.append(doc1)
documents.append(doc2)
documents.append(doc3)

vector_store.add_documents(documents, **extra_fields)
```

Then when the user queries this vector store late they can do something like this:
```
retriever.search_kwargs = {'filters': "important_field_1 eq 123"}

qa = RetrievalQA.from_chain_type(
            llm=llm,
            chain_type="stuff",
            retriever=retriever,
        )
```


#### Who can review?

Tag maintainers/contributors who might be interested:
@hwchase17
@dev2049
@ruoccofabrizio

Twitter: poshporcupine
fix anthropic chat model mutating input list

<!--
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: ChatAnthropic was mutating the input message list during formatting which isn't ideal bc you could be changing the behavior for other chat models when using the same input

#### 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:
Recursive URL loader
Labels: name: enhancement, name: area: doc loader

We may want to process load all URLs under a root directory.

For example, let's look at the [LangChain JS documentation](https://js.langchain.com/docs/).

This has many interesting child pages that we may want to read in bulk.

Of course, the `WebBaseLoader` can load a list of pages. 

But, the challenge is traversing the tree of child pages and actually assembling that list!
 
We do this using the `RecusiveUrlLoader`.

This also gives us the flexibility to exclude some children (e.g., the `api` directory with > 800 child pages).
Add KuzuQAChain
Labels: name: enhancement, 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!
-->

#### 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?
@hwchase17 

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
  - @hwchase17

  VectorStores / Retrievers / Memory
  - @dev2049

 -->

This PR adds `KuzuGraph` and `KuzuQAChain` for interacting with [Kùzu database](https://github.com/kuzudb/kuzu). Kùzu is an in-process property graph database management system (GDBMS) built for query speed and scalability. The `KuzuGraph` and `KuzuQAChain` provide the same functionality as the existing integration with NebulaGraph and Neo4j and enables query generation and question answering over Kùzu database.

A notebook example and a simple test case have also been added.
Add `_similarity_search_with_relevance_scores` in `Pinecone`

Just so it is consistent with other `VectorStore` classes.

This is a follow-up of #6056 which also discussed the potential of adding `similarity_search_by_vector_returning_embeddings` that we will continue the discussion here.

potentially related: #6286 


#### Who can review?

Tag maintainers/contributors who might be interested: @rlancemartin 

<!-- 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

 -->
Allow ids instead of keys for Redis vectorstore
Labels: name: area: vector store, name: auto:improvement

<!--
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!
-->

#### Before submitting

Redis maintains keys which have more semantics than just an identifier. As a user of langchain, I'm interested in assigning IDs to the documents that I'm ingesting, but I don't want to manually define the Redis keys with index names, key pattern, etc. manually. 

This is a problem especially when I ingest the same text multiple times (during deployment or development processes), because it will duplicate the entries with generated keys.


#### with this submission
I can specify IDs when I `add_documents` or `add_texts` and the IDs will replace the UUID part of the keys.

### More comments
For now, I added `ids` in additions to `keys` but happy to remove `keys` if allowed. Open to any other suggestions to solve the problem

#### Who can review?

Tag maintainers/contributors who might be interested:
@dev2049 @DvirDukhan

<!-- 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

 -->
Remove backticks without clear purpose from docs
Labels: name: lgtm

#### Description

- Removed two backticks surrounding the phrase "chat messages as"
- This phrase stood out among other formatted words/phrases such as `prompt`, `role`, `PromptTemplate`, etc., which all seem to have a clear function.
- `chat messages as`, formatted as such, confused me while reading, leading me to believe the backticks were misplaced.

#### Who can review?

@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

 -->
Allow PyPDFLoader to restrict page range loaded
Labels: name: area: doc loader, name: auto:improvement

When loading PDFs, I've needed to use manual workarounds to restrict page sections loaded. This is either to exclude pages that are confusing the retriever, such as tables of contents or references or to only include relevant sections of books. This PR replicates my data-cleaning workarounds.

#### Who can review?

  @eyurtsev
  @hwchase17