delayedkarma/langchain-issues huggingface dataset:
Getting "object has no field "documents" error with extended BaseRetriever classs
Labels: name: area: doc loader, name: auto:bug

### Issue you'd like to raise.

I am attempting to call an instance of ConversationalRetrieverChain with a list of dictionary objects that I've pre-processed with a similarity search and cohere reranker. I've created an extension of BaseRetriever in order to pass my list of dictionary objects to the "retriever=" parameter. However when my extended class instantiates, I get an error saying "seai_retriever object has no field "documents".  My code is below. What am I doing wrong?

```
from langchain.schema.retriever import BaseRetriever
from langchain.schema.document import Document
from langchain.callbacks.manager import CallbackManagerForRetrieverRun
from typing import List

class seai_retriever(BaseRetriever):
    def __init__(self, documents):
        self.documents = documents

    def retrieve(self, query, top_n=10):
        retrieved_docs = [doc for doc in self.documents if query.lower() in doc['content'].lower()]
        retrieved_docs = sorted(retrieved_docs, key=lambda x: x['content'].find(query), reverse=True)[:top_n]        
        return retrieved_docs
    
    def _get_relevant_documents(self, query: str, *, run_manager: CallbackManagerForRetrieverRun) -> List[Document]:
        retrieved_docs = [doc for doc in self.documents if query.lower() in doc['content'].lower()]
        retrieved_docs = sorted(retrieved_docs, key=lambda x: x['content'].find(query), reverse=True)[:top_n]        
        return retrieved_docs
```

### Suggestion:

_No response_
UnstructuredXMLLoader import error (circular import)
Labels: name: area: doc loader, name: auto:bug

### System Info

Mac Studio
M1 Max 32GB
macOS 14.1.2

Using rye
Python 3.11.6
langchain==0.0.350
langchain-community==0.0.2
langchain-core==0.1.0

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

### Reproduction

**Error**
```
File "/venv/lib/python3.11/site-packages/langchain_community/document_loaders/xml.py", line 41, in _get_elements
    from unstructured.partition.xml import partition_xml
ImportError: cannot import name 'partition_xml' from partially initialized module 'unstructured.partition.xml' (most likely due to a circular import) (/venv/lib/python3.11/site-packages/unstructured/partition/xml.py)
```

I tried to load XML document like this link(from langchain document)
https://python.langchain.com/docs/integrations/document_loaders/xml

```
from langchain.document_loaders import UnstructuredXMLLoader

loader = UnstructuredXMLLoader(
    "aaa.xml",
)
docs = loader.load()
docs[0]
```

### Expected behavior

no circular import
Update GuardrailsOutputParser for Guardrails 0.3.0, add docs
Labels: name: auto:improvement, name: auto:documentation, name: area: models, name: size:L

  - **Description:** Adding a `.from_guard` classmethod, unpacking Guardrails>=0.3.0 return type, adding docs
  - **Issue:** none
  - **Dependencies:** none
  - **Tag maintainer:** @efriis 

<!--
Please make sure your PR is passing linting and testing before submitting. Run `make format`, `make lint` and `make test` to check this locally.

See contribution guidelines for more information on how to write/run tests, lint, etc: 
https://github.com/langchain-ai/langchain/blob/master/.github/CONTRIBUTING.md

If you're adding a new integration, please include:
  1. a test for the integration, preferably unit tests that do not rely on network access,
  2. an example notebook showing its use. It lives in `docs/extras` directory.

If no one reviews your PR within a few days, please @-mention one of @baskaryan, @eyurtsev, @hwchase17.
 -->
Add Support for direct usage of llm LLamaCpp in LlamaCppEmbeddings
Labels: name: area: embeddings, name: auto:improvement, name: size:S

- **Description:** Add support for using a llm LLamaCpp directly by introducing a new parameter, `model`, to the `LlamaCppEmbeddings` constructor. This allows users to provide a llm LLamaCpp instance directly, in addition to the existing method of specifying the model path.
- **Issue:** N/A
- **Dependencies:** N/A
- **Tag maintainer:** @bfortunato
Langchain vectorstore integration with Kinetica
Labels: name: area: vector store, name: auto:enhancement, name: integration: chroma, name: size:XXL

  - **Description:** New vectorstore integration with the Kinetica database 
  - **Issue:** 
  - **Dependencies:** the Kinetica Python API `pip install gpudb==7.2.0.0b`,
  - **Tag maintainer:** @baskaryan,
  - **Twitter handle:**
Fix for openai multi tools input format.
Labels: name: area: agent, name: lgtm, name: auto:improvement, name: size:XS

 Sometimes, the tool_schema is like:
  
` {'action_name': 'search_items', 'action': {'term': 'pizza'}}`

sometimes, specially with gpt3.5 it comes like:

`{'action_name': 'search_items', 'term': 'pizza'}`

and it fails.

This PR is a way to make it work in both scenarios.

issues releated: #6624 

Please make sure your PR is passing linting and testing before submitting. Run `make format`, `make lint` and `make test` to check this locally.

See contribution guidelines for more information on how to write/run tests, lint, etc: 
https://github.com/langchain-ai/langchain/blob/master/.github/CONTRIBUTING.md

If you're adding a new integration, please include:
  1. a test for the integration, preferably unit tests that do not rely on network access,
  2. an example notebook showing its use. It lives in `docs/extras` directory.

If no one reviews your PR within a few days, please @-mention one of @baskaryan, @eyurtsev, @hwchase17.
 -->
Issue: I'm currently working on a project where I need to fetch all the sub-URLs from a website using Langchain.
Labels: name: area: doc loader, name: auto:question

### Issue you'd like to raise.


I'm currently working on a project where I need to fetch all the sub-URLs from a website using Langchain.
How can we achieve this, below is my code
`        loader = UnstructuredURLLoader(urls=urls)
        urlDocument = loader.load()
        text_splitter = RecursiveCharacterTextSplitter(chunk_size=1000, chunk_overlap=50)
        texts = text_splitter.split_documents(documents=urlDocument)`

### Suggestion:

_No response_
Bug in Text splitting while using langchain.text_splitter.split_text_on_tokens¶
Labels: name: area: doc loader, name: auto:bug

### System Info

Langchain Version = 0.0.311
Python Version = 3.9
Tried it on my local system as well on Company's hosted Jupyter Hub as well 


### Who can help?

@eyurtsev @agola11

### Information

- [X] The official example notebooks/scripts
- [X] 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

```
from langchain.text_splitter import TokenTextSplitter
token_splitter_model_name = "gpt-3.5-turbo"
SPLIT_CHUNK_SIZE = 1024
CHUNK_OVERLAP = 256
text_splitter = TokenTextSplitter.from_tiktoken_encoder(model_name=token_splitter_model_name, chunk_size=SPLIT_CHUNK_SIZE , chunk_overlap = CHUNK_OVERLAP)

blog_content= ' your text here'
blog_splits=text_splitter.split_text(blog_content)
```

### Expected behavior

The ways this token text splitter works , isn't how it is intended to work .

For Example :-
When specified chunk_size = 1024 and overlap = 256 with input text tokens = 991 , it made two chunks ;
first = token[0 : 991]
second = token[768 : 991]

but logically it should work this ways .

If input text token >1024 , there should be two chunks .
first = token[0 : 1024]
second = token[768 : ]
and so on ..............

If input text token <=1024 , there should be one chunk only .
first = token[ 0 : ]

More details on this issue raised previously :- https://github.com/langchain-ai/langchain/issues/5897
fix: correct spelling mistakes of "seperate, intialise, pre-defined" 
Labels: name: area: agent, name: lgtm, name: area: embeddings, name: area: doc loader, name: area: vector store, name: auto:nit, name: size:M

fix spellings

**seperate -> separate**: found more occurrences, see https://github.com/langchain-ai/langchain/pull/14602
**initialise -> intialize**: the latter is more common in the repo
**pre-defined > predefined**: adding a comma after a prefix is a delicate matter, but this is a generally accepted word

also, another word that appears in the repo is "fs" (stands for filesystem), e.g., in `libs/core/langchain_core/prompts/loading.py`
`    """Unified method for loading a prompt from LangChainHub or local fs."""`
Isn't "filesystem" better?
TypeError: object Document can't be used in 'await' expression
Labels: name: area: doc loader, name: auto:bug

### System Info

from langchain.document_transformers import DoctranTextTranslator
from langchain.schema import Document

documents = [Document(page_content=sample_text)]
qa_translator = DoctranTextTranslator(language="spanish")
translated_document = await qa_translator.atransform_documents(documents)


TypeError                                 Traceback (most recent call last)
[<ipython-input-18-c526f9c55393>](https://localhost:8080/#) in <cell line: 8>()
      6     openai_api_model="gpt-3.5-turbo", language="chinese")
      7 
----> 8 translated_document = await qa_translator.atransform_documents(documents)
      9 
     10 

[/usr/local/lib/python3.10/dist-packages/langchain_community/document_transformers/doctran_text_translate.py](https://localhost:8080/#) in atransform_documents(self, documents, **kwargs)
     61         ]
     62         for i, doc in enumerate(doctran_docs):
---> 63             doctran_docs[i] = await doc.translate(language=self.language).execute()
     64         return [
     65             Document(page_content=doc.transformed_content, metadata=doc.metadata)

TypeError: object Document can't be used in 'await' expression

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

### Reproduction

test

### Expected behavior

test
add api_base to _client_params (community version of #14393)
Labels: name: lgtm, name: auto:improvement, name: area: models, name: size:XS

  - **Description:** This PR adds `api_base` to `_client_params` in the `chat_model` of LiteLLM to ensure it's included in API calls. Previously, `api_base` was set on the client but was not included in the parameters passed to the completion function. This change ensures that `api_base` is correctly passed to all API calls.
  - **Issue:** #14338
  - **Tag maintainer:** @hwchase17 @agola11
  - **Twitter handle:** @LMS_David_RS
ParentDocumentRetriever.get_relevant_documents() got empty result
Labels: name: area: vector store, name: auto:bug, name: auto:question

I have two code.
The 1st code is to load PDF documents and use ParentDocumentRetriever to add_documents() and save vectorstore to local disk.
The 2nd code is to load vectorstore and call ParentDocumentRetriever.get_relevant_documents
The problem is, the ParentDocumentRetriever.get_relevant_documents() got empty result.
Any idea??
What is the inMemoryStore for??


Here are the two codes:

### the 1st code: LoadDocumentsAndSaveVectorstore.py
```
loader = DirectoryLoader('data/',
                         glob='**/*.pdf',
                         loader_cls=PyPDFLoader)
docs = loader.load()

store = InMemoryStore()
parent_splitter = RecursiveCharacterTextSplitter(chunk_size=1000)
child_splitter = RecursiveCharacterTextSplitter(chunk_size=128, chunk_overlap=64)

texts = [""]
vectorstore = FAISS.from_texts(texts, embedding_function)

retriever = ParentDocumentRetriever(
    vectorstore=vectorstore,
    docstore=store,
    child_splitter=child_splitter,
    parent_splitter=parent_splitter,
)

retriever.add_documents(docs, ids=None)
vectorstore.save_local("ppstore")

print("save data to ppstore")
```
The 1st code works fine.

The 2nd file is to load the vectorstore and query.
The strange thing is, the **retriever1.get_relevant_documents(query)** got empty result.

### the 2nd code: load vectorstore and use retriever to get relevant_documents
```
print("load ppstore")
store = InMemoryStore()
parent_splitter = RecursiveCharacterTextSplitter(chunk_size=1000)
child_splitter = RecursiveCharacterTextSplitter(chunk_size=128, chunk_overlap=64)

db = FAISS.load_local("ppstore", embedding_function)
retriever1 = ParentDocumentRetriever(
    vectorstore=db,
    docstore=store,
    child_splitter=child_splitter,
    parent_splitter=parent_splitter,
)

query = "Please describe Sardina dataset"
print("query:", query)

sub_docs = db.similarity_search(query)
print("=== check small chunk ===")
print(sub_docs[0].page_content)
print(len(sub_docs[0].page_content))  ## this respond OK, the len is a little bit smaller than 128

retrieved_docs = retriever1.get_relevant_documents(query)   ## I got empty result
print("=== check larger chunk ===")
print(retrieved_docs[0].page_content)
print(len(retrieved_docs[0].page_content)) 
```
pipeline template fixes; overlapping variables and non-pipelined variables

WIP PR
<!-- Thank you for contributing to LangChain!

Replace this entire comment with:
  - **Description:** a description of the change, 
  - **Issue:** the issue # it fixes (if applicable),
  - **Dependencies:** any dependencies required for this change,
  - **Tag maintainer:** for a quicker response, tag the relevant maintainer (see below),
  - **Twitter handle:** we announce bigger features on Twitter. If your PR gets announced, and you'd like a mention, we'll gladly shout you out!

Please make sure your PR is passing linting and testing before submitting. Run `make format`, `make lint` and `make test` to check this locally.

See contribution guidelines for more information on how to write/run tests, lint, etc: 
https://github.com/langchain-ai/langchain/blob/master/.github/CONTRIBUTING.md

If you're adding a new integration, please include:
  1. a test for the integration, preferably unit tests that do not rely on network access,
  2. an example notebook showing its use. It lives in `docs/extras` directory.

If no one reviews your PR within a few days, please @-mention one of @baskaryan, @eyurtsev, @hwchase17.
 -->
(RedisSemanticCache + ChatOpenAI + OpenAIEmbeddings) - Not working as expected - Wanted to understand, if I am doing something wrong here.
Labels: name: area: embeddings, name: auto:bug, name: area: models, name: integration: redis

### System Info

# Dependency Versions
langchain==0.0.349
langchain-community==0.0.1
langchain-core==0.0.13
openai==1.3.8

# Python Version
Python 3.11.4

# Redis Stack Version
redis-stack-server 6.2.0

### Who can help?

_No response_

### Information

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

### Related Components

- [X] LLMs/Chat Models
- [X] 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.globals import set_llm_cache
from langchain.cache import RedisSemanticCache
from langchain.embeddings import OpenAIEmbeddings
from langchain_community.chat_models import ChatOpenAI
from redis import Redis
import time

llm = ChatOpenAI(openai_api_key='<OPENAI_API_KEY>', model_name='gpt-3.5-turbo')


cache = RedisSemanticCache(redis_url="redis://localhost:6379", 
                           embedding=OpenAIEmbeddings(openai_api_key='<OPENAI_API_KEY>'), 
                           score_threshold=0.95)
set_llm_cache(cache)

start = time.time()
response = llm.predict("""Tell me about USA in only two sentences""")
print(time.time()-start)
print(response)

start = time.time()
response = llm.predict("""Tell me about INDIA in only two sentences""")
print(time.time()-start)
print(response)


start = time.time()
response = llm.predict("""What is LLMs in the context of GEN AI ?""")
print(time.time()-start)
print(response)




### Expected behavior

As the score_threshold is set to 0.98, I expect all the three prompts to give three different responses. But we are getting one response for all the three prompts.

Output from running the script : 

4.252941131591797
The United States of America is a federal republic consisting of 50 states, a federal district, five major self-governing territories, and various possessions. It is a diverse and influential country known for its cultural and economic power on the global stage.
0.3903520107269287
The United States of America is a federal republic consisting of 50 states, a federal district, five major self-governing territories, and various possessions. It is a diverse and influential country known for its cultural and economic power on the global stage.
0.6625611782073975
The United States of America is a federal republic consisting of 50 states, a federal district, five major self-governing territories, and various possessions. It is a diverse and influential country known for its cultural and economic power on the global stage.
Issue: bedrock is throwing an error for the langchain stuff method using the anthropic model for the summarization.
Labels: name: auto:bug, name: auto:question, name: area: models, name: integration: aws

### Issue you'd like to raise.

Issue 1: 
I am working on the summarization using the stuff and map-reduce of the Langchain. I have integrated it with the AWS Bedrock's anthropic llm which has a token limit of 100000. It is working fine but when the pdf with 40000 tokens is passed, the bedrock is throwing an error: 
i) with VPN connected:
An error occurred: Error raised by bedrock service: Could not connect to the endpoint URL: "https://bedrock-runtime.us-east-1.amazonaws.com/model/anthropic.claude-v2/invoke".

ii) without VPN connected:
An error occurred: Error raised by bedrock service: An error occurred (ExpiredTokenException) when calling the InvokeModel operation: The security token included in the request is expired

Any reason why this is happening? thanks in advance!

Issue 2: 
2) map-reduce takes a lot of time to produce the summary for the 40000+ tokens documents when the anthropic threshold is reduced to 40000. Sometimes it is taking a lot of time but erroring out. Any help is appreciated. Thanks in advance!


### Suggestion:

_No response_
GITLAB_URL should take default https://gitlab.com instead of error
Labels: name: lgtm, name: auto:bug, name: size:XS

The fix #14221 has broken default gitlab url which is forcing the users to specify GITLAB_URL for default one. With this fix if GITLAB_URL is not set, the default gitlab url will be taken.

  - **Description:** Add the GITHUB URL instead of None
  - **Issue:** the issue #14221 has broken the default github URL 
  - **Dependencies:** None
  - **Tag maintainer:** @hwchase17 
  - **Twitter handle:** manjunath_shiva
Milvus allows to store metadata as json field
Labels: name: lgtm, name: area: vector store, name: auto:improvement, name: size:M

Because Milvus doesn't support nullable fields, but document metadata is very rich, so it makes more sense to store it as json.

https://github.com/milvus-io/pymilvus/issues/1705#issuecomment-1731112372

<!-- Thank you for contributing to LangChain!

Replace this entire comment with:
  - **Description:** a description of the change, 
  - **Issue:** the issue # it fixes (if applicable),
  - **Dependencies:** any dependencies required for this change,
  - **Tag maintainer:** for a quicker response, tag the relevant maintainer (see below),
  - **Twitter handle:** we announce bigger features on Twitter. If your PR gets announced, and you'd like a mention, we'll gladly shout you out!

Please make sure your PR is passing linting and testing before submitting. Run `make format`, `make lint` and `make test` to check this locally.

See contribution guidelines for more information on how to write/run tests, lint, etc: 
https://github.com/langchain-ai/langchain/blob/master/.github/CONTRIBUTING.md

If you're adding a new integration, please include:
  1. a test for the integration, preferably unit tests that do not rely on network access,
  2. an example notebook showing its use. It lives in `docs/extras` directory.

If no one reviews your PR within a few days, please @-mention one of @baskaryan, @eyurtsev, @hwchase17.
 -->
Dockerfile issues when trying to build the repo using .devcontainer
Labels: name: auto:bug

### System Info

Hello, after forking and cloning the repo on my machine, I tried to open it using docker and specifically in VS Code with the option to "Reopen in Container". While building, the final command of [dev.Dockerfile](https://github.com/langchain-ai/langchain/blob/ca7da8f7ef9bc7a613ff07279c4603cad5fd175a/libs/langchain/dev.Dockerfile#L44) resulted in the following error:

```logs
#0 1.241 Directory ../core does not exist
```

After investigating, I found out that the issue lies in [pyproject.toml](https://github.com/langchain-ai/langchain/blob/ca7da8f7ef9bc7a613ff07279c4603cad5fd175a/libs/langchain/pyproject.toml) which is using relative paths like `../core` and `../community` in some occasions. Additionally, even after replacing `../` with `libs/` (which I am not sure if it breaks something else), the actual `core` and `community` directories are never copied over in [dev.Dockerfile](https://github.com/langchain-ai/langchain/blob/ca7da8f7ef9bc7a613ff07279c4603cad5fd175a/libs/langchain/dev.Dockerfile). These should also be copied in the created docker container, similarly to [line 41](https://github.com/langchain-ai/langchain/blob/ca7da8f7ef9bc7a613ff07279c4603cad5fd175a/libs/langchain/dev.Dockerfile#L41).

After making these two changes, the container was successfully built. I'll check out whether the change of paths in pyproject.toml is affecting any other files, and if not I will create a PR for this.

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

### Reproduction

Steps to reproduce:

1. Fork and clone the repo on your machine
2. Open it with VS Code (with Dev Containers extension installed)
3. Run the VS Code command: "Dev Containers: Rebuild Container"

### Expected behavior

Build the development docker container without errors