delayedkarma/langchain-issues huggingface dataset:
Create autocomment.yml
Labels: name: auto:enhancement

I have created a Workflow that automatically commits when an issue is opened, a pull request is created, an issue is closed, or an issue is assigned or unassigned.

![image](https://github.com/langchain-ai/langchain/assets/106100728/1b1eb81d-fa9d-4e53-9f3e-a853e2ddbd1c)


<!-- 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.
 -->
Add RAG template for Timescale Vector
Labels: name: area: vector store, name: auto:enhancement

<!-- 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.
 -->
Publish new versions to test PyPI on package version bump.
Labels: name: auto:improvement

When a PR updates the `pyproject.toml` version to a number that does not currently exist on PyPI (the main one, not test), a successful test run will cause the package to be built and published on test PyPI under that version by triggering the test release workflow.

We use caching to avoid spamming the PyPI metadata APIs on every PR, and instead only make one request per new version.

We have updated the release workflow to always overwrite test PyPI publishes, so I decided to not make the test publishes use `rc` versions to avoid introducing additional implementation complexity. If you feel that the extra complexity is worth it, I'm happy to switch to generating an `rc` release instead.
Relax python version and remove need for explicit setup step
Labels: name: auto:improvement

This PR addresses what seems like a unnecessary Python version restriction in the pyroject.toml specs within both Cassandra (/Astra DB) templates. With "^3.11" I got some version incompatibilities with the latest "langchain add [...]" commands, so these are now relaxed in line with the other templates I could inspect.

Incidentally, in the "entomology" template, the need for an explicit "setup" step for the user to carry on has been removed, replaced by a check-and-execute-if-necessary instruction on app startup.

Thank you for your attention!
Langchain Information Extraction
Labels: name: area: doc loader, name: auto:question, name: auto:improvement, name: area: models, name: extraction

I am trying to use Langchain information extraction chain with OpenAI. Firstly, I am reading a PDF file having some text about products or product. There is no specefic format of PDF, it can be in any format like, there can be only one product on one page or one product can be on two pages or there can be 10 products on one page. So it's completely random. How can I extract the the useful information (some key attributes) for all the products. Currently, I am using Pydantic to validate the output schema and I am using `PyPDFLoader` to load the pdf and then using the `load_and_split`.

```
loader = PyPDFLoader(file_path=file_path)
pages = loader.load_and_split()
```

And then I am looping on the pages like this:

```
llm = ChatOpenAI(temperature=0, model=model_name, openai_api_key=key)
chain = create_extraction_chain(schema, llm)

for index in range(0, len(pages)):
         output = chain.run(pages[index])
         results.append(output)
```

How can I run the extraction in such a way that it should be completely automated, currently, it is just extracting information from one page and then other and then other.
Cannot keep history of Cypher LLM in GraphCypherQAChain in the memory object
Labels: name: area: memory, name: auto:bug, name: area: models

### System Info

Python 3.9.16, langchain==0.0.322

### Who can help?

@agola11 @sudranga 

### Information

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

### Related Components

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

### Reproduction

I want to keep generated cypher queries in the memory to feed into Question/Answer LLM which leads better understanding of the context. Following example helps to reproduce error (I am not providing prompt details etc.).

* I initialize a ConversationBufferMemory to keep both question-answer as well as generated cypher queries.
```python
graph = get_neo4j_graph(neo4j_url, neo4j_db_name, neo4j_username, neo4j_password)

custom_cypher_prompt = generate_custom_cypher_prompt()

custom_qa_prompt = generate_custom_qa_prompt()

# First I did not give any input key to Memory but it gives error when there is multiple input in the prompt template
# 'question' input_key makes it work for cypher_llm and qa_llm but fails in  GraphCypherQAChain
# Since GraphCypherQAChain default input_key is 'query'
memory = ConversationBufferMemory(memory_key="chat_history", input_key='question')
readonlymemory = ReadOnlySharedMemory(memory=memory)

graph_chain = GraphCypherQAChain.from_llm(
    graph=graph,
    cypher_llm=ChatOpenAI(temperature='0', model='gpt-4', openai_api_key=openai_api_key),
    qa_llm=ChatOpenAI(temperature='0.5', model='gpt-3.5-turbo-16k', openai_api_key=openai_api_key),
    cypher_llm_kwargs={"prompt": custom_cypher_prompt, "memory": memory, "verbose": True},
    qa_llm_kwargs={"prompt": custom_qa_prompt, "memory": readonlymemory, "verbose": True},
    # Limit the number of results from the Cypher QA Chain using the top_k parameter
    top_k=5,
    # Return intermediate steps from the Cypher QA Chain
    # return_intermediate_steps=True,
    validate_cypher=True,
    verbose=True,
    memory=memory
)

response = graph_chain.run(query="<question>")
``` 

### Expected behavior

Keep generated cypher  query in the memory to feed into QA LLM as history.
Add an optional get_token function argument to AzureChatOpenAI to be called on retry
Labels: name: auto:improvement, name: area: models

### Feature request

Hi there,

Thanks you so much for this awesome library!
I have a suggestion that might improve the AzureChatOpenAI class.
 
In my company we use AzureChatOpenAI where the initialization of a `chat` object looks like this:
```    
os.environ["OPENAI_API_KEY"] = get_token().token
return AzureChatOpenAI(
    openai_api_base=AZ_OAI_API_BASE_GPT_4,
    openai_api_version="2023-05-15",
    deployment_name=AZ_OAI_DEPLOYMENT_ID_GPT_4,
    openai_api_type="azuread",
)
```

The problem is that the get_token function returns a token with a ttl of 60 minutes. 
This requires us to recreate the chat object before the expiration reaches.

I think it would be great if you could add an optional function as an argument which the AzureChatOpenAI class will trigger in the retry logic incase there is a 401 API error.

Something that looks like this:

```
class AzureChatOpenAI(ChatOpenAI):
    # ..... other properties
    token_refresh_function: Optional[Callable[[], str]] = None

   # call this on the retry function... 
   def _refresh_token_if_needed(self):
       if self.token_refresh_function:
           new_token = self.token_refresh_function()
           if new_token:
               self.client.api_key = new_token
```



### Motivation

The Azure models might have a more strict security requirements where the open_api key is a token with a short ttl.

### Your contribution

I would love to help just don't have the time right now, but I shared a few snippets that might help..
DOC: Import Error while creating SelfQueryRetriever
Labels: name: area: doc loader, name: auto:documentation

### Issue with current documentation:


Import Error while creating SelfQueryRetriever
`retriever = SelfQueryRetriever.from_llm(
    llm,
    vectordb,
    document_content_description,
    metadata_field_info,
    verbose=True)`

The documentation mentions it requires lark but doesn't explicitly mention its version. I am getting an import error.
<img width="810" alt="image" src="https://github.com/langchain-ai/langchain/assets/55703712/8380cd66-5e1f-4c91-8384-7649ca802be0">


### Idea or request for content:

The documentation should mention specifically that lark version greater then 1.1.5 is required.

`pip install lark==1.1.5`

<img width="529" alt="image" src="https://github.com/langchain-ai/langchain/assets/55703712/f054f70b-672a-4938-aaf2-4fbfa16cb051">

But this also didn't solve the issue.
AttributeError: 'PGVector' object has no attribute 'CollectionStore'. Did you mean: 'collection_name'?
Labels: name: area: vector store, name: auto:bug

### System Info

Langchain version. - 0.0.326
Python - 3.9.6

### Who can help?

_No response_

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

### Reproduction

embeddings = HuggingFaceEmbeddings(model_name='all-MiniLM-L6-v2')
CONNECTION_STRING = "postgresql+psycopg2://hwc@localhost:5432/test3"
COLLECTION_NAME = "state_of_the_union_test"

vectorestore = PGVector.from_documents(
                embedding=embeddings,
                documents=docs,
                collection_name=COLLECTION_NAME,
                connection_string=CONNECTION_STRING,
            )

Getting below error 

line 221, in get_collection
    return self.CollectionStore.get_by_name(session, self.collection_name)
           ^^^^^^^^^^^^^^^^^^^^
AttributeError: 'PGVector' object has no attribute 'CollectionStore'. Did you mean: 'collection_name'?

### Expected behavior

The embeddings should be stored in the database using pgvector.
How to use FewShotPromptTemplate and RunnableBranch combination？
Labels: name: auto:question, name: area: models

```
langchain_chain = (
        FewShotPromptTemplate(
            examples=examples,
            example_prompt=example_prompt,
            prefix=prefix,
            suffix="current time {now}\n{format_instructions} \n Question: {question} ",
            input_variables=["question", "now", "format_instructions"])
        | ChatOpenAI()
)


branch = RunnableBranch(
        (lambda x: "q1" in x["topic"].lower(), langchain_chain),
    llm=ChatTongyi())),
        (lambda x: "12" in x["topic"].lower(), anthropic_chain),
        general_chain,
    )


full_chain = {"topic": chain, "question": lambda x: x["question"], "now": now,
                  "format_instructions": format_instructions} | branch

print(full_chain.invoke({"question": "question"}))
````

I want to pass some parameters to the next chain after selecting the corresponding chain in RunnableBranch, here is the langchain_chain
LM Format Enforcer Integration + Sample Notebook
Labels: name: lgtm, name: auto:enhancement, name: area: models

## Description

This PR adds support for [lm-format-enforcer](https://github.com/noamgat/lm-format-enforcer) to LangChain. 
![image](https://raw.githubusercontent.com/noamgat/lm-format-enforcer/main/docs/Intro.webp)

The library is similar to jsonformer / RELLM which are supported in Langchain, but has several advantages such as
- Batching and Beam search support
- More complete JSON Schema support
- LLM has control over whitespace, improving quality
- Better runtime performance due to only calling the LLM's generate() function once per generate() call.

The integration is loosely based on the jsonformer integration in terms of project structure.

## Dependencies

No compile-time dependency was added, but if `lm-format-enforcer` is not installed, a runtime error will occur if it is trying to be used.

## Tests

Due to the integration modifying the internal parameters of the underlying huggingface transformer LLM, it is not possible to test without building a real LM, which requires internet access. So, similar to the jsonformer and RELLM integrations, the testing is via the notebook.

## Twitter Handle

[@noamgat](https://twitter.com/noamgat)


Looking forward to hearing feedback!
Add TileDB vectorstore implementation
Labels: name: lgtm, name: area: vector store, name: auto:enhancement

- **Description:** Add [TileDB](https://tiledb.com) vectorstore implementation. TileDB offers ANN search capabilities using the [TileDB-Vector-Search](https://github.com/TileDB-Inc/TileDB-Vector-Search) module. It provides serverless execution of ANN queries and storage of vector indexes both on local disk and cloud object stores (i.e. AWS S3). More details in:
  - [Why TileDB as a Vector Database](https://tiledb.com/blog/why-tiledb-as-a-vector-database)
  - [TileDB 101: Vector Search](https://tiledb.com/blog/tiledb-101-vector-search)
- **Twitter handle:** @tiledb
Issue: Creating Memory of QAChain , Making the llm not to answer from its own knowledge but rely on the context we provided
Labels: name: area: memory, name: auto:question, name: auto:improvement, name: area: models

### Issue you'd like to raise.

I have created a retrieval QA project. In this project, I want to add memory to LLM so that it can also remember the previous chat. I have configured the LLM not to answer from its own knowledge but from the context I provided, and it is working fine. However, when I add memory to it, it starts to answer from its own knowledge if it is out of context. I just want the LLM to answer based on the context, remember the previous chat, and if the answer is out of context, it should simply state that it is out of context or something similar. Kindly help me or suggest me something which can work.

### Suggestion:

_No response_
Issue: Amazon Bedrock Cohere Command - Malformed input request: 2 schema violations found, please reformat your input and try again.
Labels: name: auto:bug, name: area: models, name: integration: aws

### Issue you'd like to raise.

I've have been trying to work with AWS bedrock Cohere command LLM with Langchain and I'm referring [https://github.com/aws-samples/rag-using-langchain-amazon-bedrock-and-opensearch/blob/main/ask-bedrock-with-rag.py](url) as source. 
**Below are few snippet of code that I'm working with,**

def create_bedrock_llm(bedrock_client):
    bedrock_llm = Bedrock(
        model_id="cohere.command-text-v14", 
        client=bedrock_client,
        verbose = True,
        model_kwargs={'temperature': 0}
        )
    return bedrock_llm

bedrock_client = bedrock_client = boto3.client(service_name="bedrock-runtime", region_name="us-east-1")
llm = create_bedrock_llm(bedrock_client)
template = """"Your are a expert financial reporter who analyzes performance of the company. The relevant information for answering the question is given below. Try to give detailed answer using the context available. If you don't know the answer, just say that you don't know, don't try to make up an answer.

{context}

Question: {question}

Answer:"""
prompt = PromptTemplate(template=template,
                            input_variables=['context', 'question'])

embedding = SentenceTransformerEmbeddings(model_name="all-MiniLM-L6-v2")
db = Chroma(persist_directory=DB_CHROMA_PATH, embedding_function=embedding)
retriever=db.as_retriever(search_kwargs={'k': 3})

qa = RetrievalQA.from_chain_type(llm=llm, 
                                     chain_type="stuff", 
                                     retriever=retriever,
                                     return_source_documents=True,
                                     chain_type_kwargs={"prompt": prompt, "verbose": True},
                                     verbose=True)
                                     

while True:
    query = input("\nEnter the query\n")
    if query.lower() == 'exit':
        break
    res = qa(query)
    print(res)
    
**Error**:
ValueError: Error raised by bedrock service: An error occurred (ValidationException) when calling the InvokeModel operation: Malformed input request: 2 schema violations found, please reformat your input and try again.

### Suggestion:

I have tried with API request using invoke_model() function with the same prompt schema which worked perfectly fine and response was recieved.
PGVector __post_init__ was removed in 0.0.326
Labels: name: area: vector store, name: auto:bug

### System Info

Langchain: 0.0.326
__post_init__ in __init__ accidentally removed in: https://github.com/langchain-ai/langchain/commit/2c58dca5f0ca946421ef9b7cc8149d38537ee466


### Who can help?

_No response_

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

### Reproduction

1. Use PGVector
2. lib/python3.11/site-packages/langchain/vectorstores/pgvector.py", line 497, in from_texts
    embeddings = embedding.embed_documents(list(texts))
                 ^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'embed_documents'


### Expected behavior

PGVector should have __post_init__ to initialize the collection
Better Math Chain
Labels: name: auto:enhancement, name: area: models

### Feature request

Currently, there are two separate chains for math: LLMSymbolicMathChain and LLMMathChain. Is there a way to get the best of both words?

### Motivation

Sometimes it is better to use one over the other for my app, but currently, I can only use one. 

### Your contribution

Not that I know of.
refactor: Code Refactoring of Vertex AI Components
Labels: name: auto:refactor, name: area: models

- Improved Readability/Efficiency by Code Refactoring of Vertex AI Components
- Fixes #11961
  - Adds error handling for aiplatform versions <1.35.0
 
<!-- 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.
 -->
add emailfrompdf capability
Labels: name: area: doc loader, name: auto:enhancement

Description:
This adds a document loader to extract content and metadata from email and email-like memos which have been saved in .pdf format rather than retrieved from outlook, exchange or gmail or saved in ,eml format. metadata includes, to, cc, from, subject, date and the names of any inline-images or attachments.
This is likely to be especially useful for wading through a response to public record requests.

Issue:

email with metadata from pdfs  langchain-ai/langchain#12494

Dependencies:
dateparser
pdf2image
pytesseract

Twitter handle:
tevslin
DataFrameLoader accepts ONLY one column and by default labeled as "text"
Labels: name: area: doc loader, name: auto:question, name: auto:improvement

I am working with a DataFrame that has multiple columns to get their text. Why is the method only accepts one column as input?

Here is the reference to the line of the code:

https://github.com/langchain-ai/langchain/blob/481bf6fae695653c52b26895292a40cf010c08e2/libs/langchain/langchain/document_loaders/dataframe.py#L36C71-L36C71
Fix BeautifulSoupTransformer: no more duplicates and correct order of tags + tests
Labels: name: auto:improvement

  - **Description:** Fix extracting nested tags in correct order and without duplication
  - **Issue:** None
  - **Dependencies:** None
  - **Tag maintainer:** @baskaryan reviewed and merged my previous similar PR
  - **Twitter handle:** peter_v

Run `make format`, `make lint` and `make test` => OK
docs: removed DocCardList in `guides/` indexes
Labels: name: auto:documentation

Removed unnecessary `DocCardList` in the `index` files. They create unnecessary duplicate of ToC in the end of pages (we also have ToC on sidebars).

this PR is continuing after #12745 12307
Problem statement:
Here is an [example](https://python.langchain.com/docs/integrations/document_transformers).
We have a sidebar with Toc and we also have a ToC at the end of the page.
The ToC at the end of the page is not necessary and it is confusing when we mix the index page styles, moreover, it requires manual work.
So, instead of the generated index.mdx pages with CardLists, I've created them manually with small text about an entity