seansullivan/Langchain-Docs huggingface dataset:
## pirate-speak-configurable

This template converts user input into pirate speak. It shows how you can allow `configurable_alternatives` in the Runnable, allowing you to select from OpenAI, Anthropic, or Cohere as your LLM Provider in the playground (or via API).

## Environment Setup[​](#environment-setup "Direct link to Environment Setup")

Set the following environment variables to access all 3 configurable alternative model providers:

*   `OPENAI_API_KEY`
*   `ANTHROPIC_API_KEY`
*   `COHERE_API_KEY`

## Usage[​](#usage "Direct link to Usage")

To use this package, you should first have the LangChain CLI installed:

```
pip install -U langchain-cli
```

To create a new LangChain project and install this as the only package, you can do:

```
langchain app new my-app --package pirate-speak-configurable
```

If you want to add this to an existing project, you can just run:

```
langchain app add pirate-speak-configurable
```

And add the following code to your `server.py` file:

```
from pirate_speak_configurable import chain as pirate_speak_configurable_chainadd_routes(app, pirate_speak_configurable_chain, path="/pirate-speak-configurable")
```

(Optional) Let's now configure LangSmith. LangSmith will help us trace, monitor and debug LangChain applications. You can sign up for LangSmith [here](https://smith.langchain.com/). If you don't have access, you can skip this section

```
export LANGCHAIN_TRACING_V2=trueexport LANGCHAIN_API_KEY=<your-api-key>export LANGCHAIN_PROJECT=<your-project>  # if not specified, defaults to "default"
```

If you are inside this directory, then you can spin up a LangServe instance directly by:

This will start the FastAPI app with a server is running locally at [http://localhost:8000](http://localhost:8000/)

We can see all templates at [http://127.0.0.1:8000/docs](http://127.0.0.1:8000/docs) We can access the playground at [http://127.0.0.1:8000/pirate-speak-configurable/playground](http://127.0.0.1:8000/pirate-speak-configurable/playground)

We can access the template from code with:

```
from langserve.client import RemoteRunnablerunnable = RemoteRunnable("http://localhost:8000/pirate-speak-configurable")
```

* * *

#### Help us out by providing feedback on this documentation page:
## rag-pinecone-multi-query

This template performs RAG using Pinecone and OpenAI with a multi-query retriever.

It uses an LLM to generate multiple queries from different perspectives based on the user's input query.

For each query, it retrieves a set of relevant documents and takes the unique union across all queries for answer synthesis.

## Environment Setup[​](#environment-setup "Direct link to Environment Setup")

This template uses Pinecone as a vectorstore and requires that `PINECONE_API_KEY`, `PINECONE_ENVIRONMENT`, and `PINECONE_INDEX` are set.

Set the `OPENAI_API_KEY` environment variable to access the OpenAI models.

## Usage[​](#usage "Direct link to Usage")

To use this package, you should first install the LangChain CLI:

```
pip install -U langchain-cli
```

To create a new LangChain project and install this package, do:

```
langchain app new my-app --package rag-pinecone-multi-query
```

To add this package to an existing project, run:

```
langchain app add rag-pinecone-multi-query
```

And add the following code to your `server.py` file:

```
from rag_pinecone_multi_query import chain as rag_pinecone_multi_query_chainadd_routes(app, rag_pinecone_multi_query_chain, path="/rag-pinecone-multi-query")
```

(Optional) Now, let's configure LangSmith. LangSmith will help us trace, monitor, and debug LangChain applications. You can sign up for LangSmith [here](https://smith.langchain.com/). If you don't have access, you can skip this section

```
export LANGCHAIN_TRACING_V2=trueexport LANGCHAIN_API_KEY=<your-api-key>export LANGCHAIN_PROJECT=<your-project>  # if not specified, defaults to "default"
```

If you are inside this directory, then you can spin up a LangServe instance directly by:

This will start the FastAPI app with a server running locally at [http://localhost:8000](http://localhost:8000/)

You can see all templates at [http://127.0.0.1:8000/docs](http://127.0.0.1:8000/docs) You can access the playground at [http://127.0.0.1:8000/rag-pinecone-multi-query/playground](http://127.0.0.1:8000/rag-pinecone-multi-query/playground)

To access the template from code, use:

```
from langserve.client import RemoteRunnablerunnable = RemoteRunnable("http://localhost:8000/rag-pinecone-multi-query")
```
## pirate-speak

This template converts user input into pirate speak.

## Environment Setup[​](#environment-setup "Direct link to Environment Setup")

Set the `OPENAI_API_KEY` environment variable to access the OpenAI models.

## Usage[​](#usage "Direct link to Usage")

To use this package, you should first have the LangChain CLI installed:

```
pip install -U langchain-cli
```

To create a new LangChain project and install this as the only package, you can do:

```
langchain app new my-app --package pirate-speak
```

If you want to add this to an existing project, you can just run:

```
langchain app add pirate-speak
```

And add the following code to your `server.py` file:

```
from pirate_speak.chain import chain as pirate_speak_chainadd_routes(app, pirate_speak_chain, path="/pirate-speak")
```

(Optional) Let's now configure LangSmith. LangSmith will help us trace, monitor and debug LangChain applications. You can sign up for LangSmith [here](https://smith.langchain.com/). If you don't have access, you can skip this section

```
export LANGCHAIN_TRACING_V2=trueexport LANGCHAIN_API_KEY=<your-api-key>export LANGCHAIN_PROJECT=<your-project>  # if not specified, defaults to "default"
```

If you are inside this directory, then you can spin up a LangServe instance directly by:

This will start the FastAPI app with a server is running locally at [http://localhost:8000](http://localhost:8000/)

We can see all templates at [http://127.0.0.1:8000/docs](http://127.0.0.1:8000/docs) We can access the playground at [http://127.0.0.1:8000/pirate-speak/playground](http://127.0.0.1:8000/pirate-speak/playground)

We can access the template from code with:

```
from langserve.client import RemoteRunnablerunnable = RemoteRunnable("http://localhost:8000/pirate-speak")
```

* * *

#### Help us out by providing feedback on this documentation page:
## rag-pinecone-rerank

This template performs RAG using Pinecone and OpenAI along with [Cohere to perform re-ranking](https://txt.cohere.com/rerank/) on returned documents.

Re-ranking provides a way to rank retrieved documents using specified filters or criteria.

## Environment Setup[​](#environment-setup "Direct link to Environment Setup")

This template uses Pinecone as a vectorstore and requires that `PINECONE_API_KEY`, `PINECONE_ENVIRONMENT`, and `PINECONE_INDEX` are set.

Set the `OPENAI_API_KEY` environment variable to access the OpenAI models.

Set the `COHERE_API_KEY` environment variable to access the Cohere ReRank.

## Usage[​](#usage "Direct link to Usage")

To use this package, you should first have the LangChain CLI installed:

```
pip install -U langchain-cli
```

To create a new LangChain project and install this as the only package, you can do:

```
langchain app new my-app --package rag-pinecone-rerank
```

If you want to add this to an existing project, you can just run:

```
langchain app add rag-pinecone-rerank
```

And add the following code to your `server.py` file:

```
from rag_pinecone_rerank import chain as rag_pinecone_rerank_chainadd_routes(app, rag_pinecone_rerank_chain, path="/rag-pinecone-rerank")
```

(Optional) Let's now configure LangSmith. LangSmith will help us trace, monitor and debug LangChain applications. You can sign up for LangSmith [here](https://smith.langchain.com/). If you don't have access, you can skip this section

```
export LANGCHAIN_TRACING_V2=trueexport LANGCHAIN_API_KEY=<your-api-key>export LANGCHAIN_PROJECT=<your-project>  # if not specified, defaults to "default"
```

If you are inside this directory, then you can spin up a LangServe instance directly by:

This will start the FastAPI app with a server is running locally at [http://localhost:8000](http://localhost:8000/)

We can see all templates at [http://127.0.0.1:8000/docs](http://127.0.0.1:8000/docs) We can access the playground at [http://127.0.0.1:8000/rag-pinecone-rerank/playground](http://127.0.0.1:8000/rag-pinecone-rerank/playground)

We can access the template from code with:

```
from langserve.client import RemoteRunnablerunnable = RemoteRunnable("http://localhost:8000/rag-pinecone-rerank")
```
## hyde

This template uses HyDE with RAG.

Hyde is a retrieval method that stands for Hypothetical Document Embeddings (HyDE). It is a method used to enhance retrieval by generating a hypothetical document for an incoming query.

The document is then embedded, and that embedding is utilized to look up real documents that are similar to the hypothetical document.

The underlying concept is that the hypothetical document may be closer in the embedding space than the query.

For a more detailed description, see the paper [here](https://arxiv.org/abs/2212.10496).

## Environment Setup[​](#environment-setup "Direct link to Environment Setup")

Set the `OPENAI_API_KEY` environment variable to access the OpenAI models.

## Usage[​](#usage "Direct link to Usage")

To use this package, you should first have the LangChain CLI installed:

```
pip install -U langchain-cli
```

To create a new LangChain project and install this as the only package, you can do:

```
langchain app new my-app --package hyde
```

If you want to add this to an existing project, you can just run:

And add the following code to your `server.py` file:

```
from hyde.chain import chain as hyde_chainadd_routes(app, hyde_chain, path="/hyde")
```

(Optional) Let's now configure LangSmith. LangSmith will help us trace, monitor and debug LangChain applications. You can sign up for LangSmith [here](https://smith.langchain.com/). If you don't have access, you can skip this section

```
export LANGCHAIN_TRACING_V2=trueexport LANGCHAIN_API_KEY=<your-api-key>export LANGCHAIN_PROJECT=<your-project>  # if not specified, defaults to "default"
```

If you are inside this directory, then you can spin up a LangServe instance directly by:

This will start the FastAPI app with a server is running locally at [http://localhost:8000](http://localhost:8000/)

We can see all templates at [http://127.0.0.1:8000/docs](http://127.0.0.1:8000/docs) We can access the playground at [http://127.0.0.1:8000/hyde/playground](http://127.0.0.1:8000/hyde/playground)

We can access the template from code with:

```
from langserve.client import RemoteRunnablerunnable = RemoteRunnable("http://localhost:8000/hyde")
```
## Hybrid Search in Weaviate

This template shows you how to use the hybrid search feature in Weaviate. Hybrid search combines multiple search algorithms to improve the accuracy and relevance of search results.

Weaviate uses both sparse and dense vectors to represent the meaning and context of search queries and documents. The results use a combination of `bm25` and vector search ranking to return the top results.

## Configurations[​](#configurations "Direct link to Configurations")

Connect to your hosted Weaviate Vectorstore by setting a few env variables in `chain.py`:

*   `WEAVIATE_ENVIRONMENT`
*   `WEAVIATE_API_KEY`

You will also need to set your `OPENAI_API_KEY` to use the OpenAI models.

## Get Started[​](#get-started "Direct link to Get Started")

To use this package, you should first have the LangChain CLI installed:

```
pip install -U langchain-cli
```

To create a new LangChain project and install this as the only package, you can do:

```
langchain app new my-app --package hybrid-search-weaviate
```

If you want to add this to an existing project, you can just run:

```
langchain app add hybrid-search-weaviate
```

And add the following code to your `server.py` file:

```
from hybrid_search_weaviate import chain as hybrid_search_weaviate_chainadd_routes(app, hybrid_search_weaviate_chain, path="/hybrid-search-weaviate")
```

(Optional) Let's now configure LangSmith. LangSmith will help us trace, monitor and debug LangChain applications. You can sign up for LangSmith [here](https://smith.langchain.com/). If you don't have access, you can skip this section

```
export LANGCHAIN_TRACING_V2=trueexport LANGCHAIN_API_KEY=<your-api-key>export LANGCHAIN_PROJECT=<your-project>  # if not specified, defaults to "default"
```

If you are inside this directory, then you can spin up a LangServe instance directly by:

This will start the FastAPI app with a server is running locally at [http://localhost:8000](http://localhost:8000/)

We can see all templates at [http://127.0.0.1:8000/docs](http://127.0.0.1:8000/docs) We can access the playground at [http://127.0.0.1:8000/hybrid-search-weaviate/playground](http://127.0.0.1:8000/hybrid-search-weaviate/playground)

We can access the template from code with:

```
from langserve.client import RemoteRunnablerunnable = RemoteRunnable("http://localhost:8000/hybrid-search-weaviate")
```

* * *

#### Help us out by providing feedback on this documentation page:
## rag-pinecone

This template performs RAG using Pinecone and OpenAI.

## Environment Setup[​](#environment-setup "Direct link to Environment Setup")

This template uses Pinecone as a vectorstore and requires that `PINECONE_API_KEY`, `PINECONE_ENVIRONMENT`, and `PINECONE_INDEX` are set.

Set the `OPENAI_API_KEY` environment variable to access the OpenAI models.

## Usage[​](#usage "Direct link to Usage")

To use this package, you should first have the LangChain CLI installed:

```
pip install -U langchain-cli
```

To create a new LangChain project and install this as the only package, you can do:

```
langchain app new my-app --package rag-pinecone
```

If you want to add this to an existing project, you can just run:

```
langchain app add rag-pinecone
```

And add the following code to your `server.py` file:

```
from rag_pinecone import chain as rag_pinecone_chainadd_routes(app, rag_pinecone_chain, path="/rag-pinecone")
```

(Optional) Let's now configure LangSmith. LangSmith will help us trace, monitor and debug LangChain applications. You can sign up for LangSmith [here](https://smith.langchain.com/). If you don't have access, you can skip this section

```
export LANGCHAIN_TRACING_V2=trueexport LANGCHAIN_API_KEY=<your-api-key>export LANGCHAIN_PROJECT=<your-project>  # if not specified, defaults to "default"
```

If you are inside this directory, then you can spin up a LangServe instance directly by:

This will start the FastAPI app with a server is running locally at [http://localhost:8000](http://localhost:8000/)

We can see all templates at [http://127.0.0.1:8000/docs](http://127.0.0.1:8000/docs) We can access the playground at [http://127.0.0.1:8000/rag-pinecone/playground](http://127.0.0.1:8000/rag-pinecone/playground)

We can access the template from code with:

```
from langserve.client import RemoteRunnablerunnable = RemoteRunnable("http://localhost:8000/rag-pinecone")
```

* * *

#### Help us out by providing feedback on this documentation page:
## propositional-retrieval

This template demonstrates the multi-vector indexing strategy proposed by Chen, et. al.'s [Dense X Retrieval: What Retrieval Granularity Should We Use?](https://arxiv.org/abs/2312.06648). The prompt, which you can [try out on the hub](https://smith.langchain.com/hub/wfh/proposal-indexing), directs an LLM to generate de-contextualized "propositions" which can be vectorized to increase the retrieval accuracy. You can see the full definition in `proposal_chain.py`.

## Storage[​](#storage "Direct link to Storage")

For this demo, we index a simple academic paper using the RecursiveUrlLoader, and store all retriever information locally (using chroma and a bytestore stored on the local filesystem). You can modify the storage layer in `storage.py`.

## Environment Setup[​](#environment-setup "Direct link to Environment Setup")

Set the `OPENAI_API_KEY` environment variable to access `gpt-3.5` and the OpenAI Embeddings classes.

## Indexing[​](#indexing "Direct link to Indexing")

Create the index by running the following:

```
poetry installpoetry run python propositional_retrieval/ingest.py
```

## Usage[​](#usage "Direct link to Usage")

To use this package, you should first have the LangChain CLI installed:

```
pip install -U langchain-cli
```

To create a new LangChain project and install this as the only package, you can do:

```
langchain app new my-app --package propositional-retrieval
```

If you want to add this to an existing project, you can just run:

```
langchain app add propositional-retrieval
```

And add the following code to your `server.py` file:

```
from propositional_retrieval import chainadd_routes(app, chain, path="/propositional-retrieval")
```

(Optional) Let's now configure LangSmith. LangSmith will help us trace, monitor and debug LangChain applications. You can sign up for LangSmith [here](https://smith.langchain.com/). If you don't have access, you can skip this section

```
export LANGCHAIN_TRACING_V2=trueexport LANGCHAIN_API_KEY=<your-api-key>export LANGCHAIN_PROJECT=<your-project>  # if not specified, defaults to "default"
```

If you are inside this directory, then you can spin up a LangServe instance directly by:

This will start the FastAPI app with a server is running locally at [http://localhost:8000](http://localhost:8000/)

We can see all templates at [http://127.0.0.1:8000/docs](http://127.0.0.1:8000/docs) We can access the playground at [http://127.0.0.1:8000/propositional-retrieval/playground](http://127.0.0.1:8000/propositional-retrieval/playground)

We can access the template from code with:

```
from langserve.client import RemoteRunnablerunnable = RemoteRunnable("http://localhost:8000/propositional-retrieval")
```
## plate-chain

This template enables parsing of data from laboratory plates.

In the context of biochemistry or molecular biology, laboratory plates are commonly used tools to hold samples in a grid-like format.

This can parse the resulting data into standardized (e.g., JSON) format for further processing.

## Environment Setup[​](#environment-setup "Direct link to Environment Setup")

Set the `OPENAI_API_KEY` environment variable to access the OpenAI models.

## Usage[​](#usage "Direct link to Usage")

To utilize plate-chain, you must have the LangChain CLI installed:

```
pip install -U langchain-cli
```

Creating a new LangChain project and installing plate-chain as the only package can be done with:

```
langchain app new my-app --package plate-chain
```

If you wish to add this to an existing project, simply run:

```
langchain app add plate-chain
```

Then add the following code to your `server.py` file:

```
from plate_chain import chain as plate_chainadd_routes(app, plate_chain, path="/plate-chain")
```

(Optional) For configuring LangSmith, which helps trace, monitor and debug LangChain applications, use the following code:

```
export LANGCHAIN_TRACING_V2=trueexport LANGCHAIN_API_KEY=<your-api-key>export LANGCHAIN_PROJECT=<your-project>  # if not specified, defaults to "default"
```

If you're in this directory, you can start a LangServe instance directly by:

This starts the FastAPI app with a server running locally at [http://localhost:8000](http://localhost:8000/)

All templates can be viewed at [http://127.0.0.1:8000/docs](http://127.0.0.1:8000/docs) Access the playground at [http://127.0.0.1:8000/plate-chain/playground](http://127.0.0.1:8000/plate-chain/playground)

You can access the template from code with:

```
from langserve.client import RemoteRunnablerunnable = RemoteRunnable("http://localhost:8000/plate-chain")
```

* * *

#### Help us out by providing feedback on this documentation page:
## python-lint

This agent specializes in generating high-quality Python code with a focus on proper formatting and linting. It uses `black`, `ruff`, and `mypy` to ensure the code meets standard quality checks.

This streamlines the coding process by integrating and responding to these checks, resulting in reliable and consistent code output.

It cannot actually execute the code it writes, as code execution may introduce additional dependencies and potential security vulnerabilities. This makes the agent both a secure and efficient solution for code generation tasks.

You can use it to generate Python code directly, or network it with planning and execution agents.

## Environment Setup[​](#environment-setup "Direct link to Environment Setup")

*   Install `black`, `ruff`, and `mypy`: `pip install -U black ruff mypy`
*   Set `OPENAI_API_KEY` environment variable.

## Usage[​](#usage "Direct link to Usage")

To use this package, you should first have the LangChain CLI installed:

```
pip install -U langchain-cli
```

To create a new LangChain project and install this as the only package, you can do:

```
langchain app new my-app --package python-lint
```

If you want to add this to an existing project, you can just run:

```
langchain app add python-lint
```

And add the following code to your `server.py` file:

```
from python_lint import agent_executor as python_lint_agentadd_routes(app, python_lint_agent, path="/python-lint")
```

(Optional) Let's now configure LangSmith. LangSmith will help us trace, monitor and debug LangChain applications. You can sign up for LangSmith [here](https://smith.langchain.com/). If you don't have access, you can skip this section

```
export LANGCHAIN_TRACING_V2=trueexport LANGCHAIN_API_KEY=<your-api-key>export LANGCHAIN_PROJECT=<your-project>  # if not specified, defaults to "default"
```

If you are inside this directory, then you can spin up a LangServe instance directly by:

This will start the FastAPI app with a server is running locally at [http://localhost:8000](http://localhost:8000/)

We can see all templates at [http://127.0.0.1:8000/docs](http://127.0.0.1:8000/docs) We can access the playground at [http://127.0.0.1:8000/python-lint/playground](http://127.0.0.1:8000/python-lint/playground)

We can access the template from code with:

```
from langserve.client import RemoteRunnablerunnable = RemoteRunnable("http://localhost:8000/python-lint")
```
## llama2-functions

This template performs extraction of structured data from unstructured data using a [LLaMA2 model that supports a specified JSON output schema](https://github.com/ggerganov/llama.cpp/blob/master/grammars/README.md).

The extraction schema can be set in `chain.py`.

## Environment Setup[​](#environment-setup "Direct link to Environment Setup")

This will use a [LLaMA2-13b model hosted by Replicate](https://replicate.com/andreasjansson/llama-2-13b-chat-gguf/versions).

Ensure that `REPLICATE_API_TOKEN` is set in your environment.

## Usage[​](#usage "Direct link to Usage")

To use this package, you should first have the LangChain CLI installed:

```
pip install -U langchain-cli
```

To create a new LangChain project and install this as the only package, you can do:

```
langchain app new my-app --package llama2-functions
```

If you want to add this to an existing project, you can just run:

```
langchain app add llama2-functions
```

And add the following code to your `server.py` file:

```
from llama2_functions import chain as llama2_functions_chainadd_routes(app, llama2_functions_chain, path="/llama2-functions")
```

(Optional) Let's now configure LangSmith. LangSmith will help us trace, monitor and debug LangChain applications. You can sign up for LangSmith [here](https://smith.langchain.com/). If you don't have access, you can skip this section

```
export LANGCHAIN_TRACING_V2=trueexport LANGCHAIN_API_KEY=<your-api-key>export LANGCHAIN_PROJECT=<your-project>  # if not specified, defaults to "default"
```

If you are inside this directory, then you can spin up a LangServe instance directly by:

This will start the FastAPI app with a server is running locally at [http://localhost:8000](http://localhost:8000/)

We can see all templates at [http://127.0.0.1:8000/docs](http://127.0.0.1:8000/docs) We can access the playground at [http://127.0.0.1:8000/llama2-functions/playground](http://127.0.0.1:8000/llama2-functions/playground)

We can access the template from code with:

```
from langserve.client import RemoteRunnablerunnable = RemoteRunnable("http://localhost:8000/llama2-functions")
```

* * *

#### Help us out by providing feedback on this documentation page:
## rag-self-query

This template performs RAG using the self-query retrieval technique. The main idea is to let an LLM convert unstructured queries into structured queries. See the [docs for more on how this works](https://python.langchain.com/docs/modules/data_connection/retrievers/self_query).

## Environment Setup[​](#environment-setup "Direct link to Environment Setup")

In this template we'll use OpenAI models and an Elasticsearch vector store, but the approach generalizes to all LLMs/ChatModels and [a number of vector stores](https://python.langchain.com/docs/integrations/retrievers/self_query/).

Set the `OPENAI_API_KEY` environment variable to access the OpenAI models.

To connect to your Elasticsearch instance, use the following environment variables:

```
export ELASTIC_CLOUD_ID = <ClOUD_ID>export ELASTIC_USERNAME = <ClOUD_USERNAME>export ELASTIC_PASSWORD = <ClOUD_PASSWORD>
```

For local development with Docker, use:

```
export ES_URL = "http://localhost:9200"docker run -p 9200:9200 -e "discovery.type=single-node" -e "xpack.security.enabled=false" -e "xpack.security.http.ssl.enabled=false" docker.elastic.co/elasticsearch/elasticsearch:8.9.0
```

## Usage[​](#usage "Direct link to Usage")

To use this package, you should first have the LangChain CLI installed:

```
pip install -U "langchain-cli[serve]"
```

To create a new LangChain project and install this as the only package, you can do:

```
langchain app new my-app --package rag-self-query
```

If you want to add this to an existing project, you can just run:

```
langchain app add rag-self-query
```

And add the following code to your `server.py` file:

```
from rag_self_query import chainadd_routes(app, chain, path="/rag-elasticsearch")
```

To populate the vector store with the sample data, from the root of the directory run:

(Optional) Let's now configure LangSmith. LangSmith will help us trace, monitor and debug LangChain applications. You can sign up for LangSmith [here](https://smith.langchain.com/). If you don't have access, you can skip this section

```
export LANGCHAIN_TRACING_V2=trueexport LANGCHAIN_API_KEY=<your-api-key>export LANGCHAIN_PROJECT=<your-project>  # if not specified, defaults to "default"
```

If you are inside this directory, then you can spin up a LangServe instance directly by:

This will start the FastAPI app with a server is running locally at [http://localhost:8000](http://localhost:8000/)

We can see all templates at [http://127.0.0.1:8000/docs](http://127.0.0.1:8000/docs) We can access the playground at [http://127.0.0.1:8000/rag-elasticsearch/playground](http://127.0.0.1:8000/rag-elasticsearch/playground)

We can access the template from code with:

```
from langserve.client import RemoteRunnablerunnable = RemoteRunnable("http://localhost:8000/rag-self-query")
```
## rag-astradb

This template will perform RAG using Astra DB (`AstraDB` vector store class)

## Environment Setup[​](#environment-setup "Direct link to Environment Setup")

An [Astra DB](https://astra.datastax.com/) database is required; free tier is fine.

*   You need the database **API endpoint** (such as `https://0123...-us-east1.apps.astra.datastax.com`) ...
*   ... and a **token** (`AstraCS:...`).

Also, an **OpenAI API Key** is required. _Note that out-of-the-box this demo supports OpenAI only, unless you tinker with the code._

Provide the connection parameters and secrets through environment variables. Please refer to `.env.template` for the variable names.

## Usage[​](#usage "Direct link to Usage")

To use this package, you should first have the LangChain CLI installed:

```
pip install -U "langchain-cli[serve]"
```

To create a new LangChain project and install this as the only package, you can do:

```
langchain app new my-app --package rag-astradb
```

If you want to add this to an existing project, you can just run:

```
langchain app add rag-astradb
```

And add the following code to your `server.py` file:

```
from astradb_entomology_rag import chain as astradb_entomology_rag_chainadd_routes(app, astradb_entomology_rag_chain, path="/rag-astradb")
```

(Optional) Let's now configure LangSmith. LangSmith will help us trace, monitor and debug LangChain applications. You can sign up for LangSmith [here](https://smith.langchain.com/). If you don't have access, you can skip this section

```
export LANGCHAIN_TRACING_V2=trueexport LANGCHAIN_API_KEY=<your-api-key>export LANGCHAIN_PROJECT=<your-project>  # if not specified, defaults to "default"
```

If you are inside this directory, then you can spin up a LangServe instance directly by:

This will start the FastAPI app with a server is running locally at [http://localhost:8000](http://localhost:8000/)

We can see all templates at [http://127.0.0.1:8000/docs](http://127.0.0.1:8000/docs) We can access the playground at [http://127.0.0.1:8000/rag-astradb/playground](http://127.0.0.1:8000/rag-astradb/playground)

We can access the template from code with:

```
from langserve.client import RemoteRunnablerunnable = RemoteRunnable("http://localhost:8000/rag-astradb")
```

## Reference[​](#reference "Direct link to Reference")

Stand-alone repo with LangServe chain: [here](https://github.com/hemidactylus/langserve_astradb_entomology_rag).
## rag-redis

This template performs RAG using Redis (vector database) and OpenAI (LLM) on financial 10k filings docs for Nike.

It relies on the sentence transformer `all-MiniLM-L6-v2` for embedding chunks of the pdf and user questions.

## Environment Setup[​](#environment-setup "Direct link to Environment Setup")

Set the `OPENAI_API_KEY` environment variable to access the [OpenAI](https://platform.openai.com/) models:

```
export OPENAI_API_KEY= <YOUR OPENAI API KEY>
```

Set the following [Redis](https://redis.com/try-free) environment variables:

```
export REDIS_HOST = <YOUR REDIS HOST>export REDIS_PORT = <YOUR REDIS PORT>export REDIS_USER = <YOUR REDIS USER NAME>export REDIS_PASSWORD = <YOUR REDIS PASSWORD>
```

## Supported Settings[​](#supported-settings "Direct link to Supported Settings")

We use a variety of environment variables to configure this application

| Environment Variable | Description | Default Value |
| --- | --- | --- |
| `DEBUG` | Enable or disable Langchain debugging logs | True |
| `REDIS_HOST` | Hostname for the Redis server | "localhost" |
| `REDIS_PORT` | Port for the Redis server | 6379 |
| `REDIS_USER` | User for the Redis server | ""  |
| `REDIS_PASSWORD` | Password for the Redis server | ""  |
| `REDIS_URL` | Full URL for connecting to Redis | `None`, Constructed from user, password, host, and port if not provided |
| `INDEX_NAME` | Name of the vector index | "rag-redis" |

## Usage[​](#usage "Direct link to Usage")

To use this package, you should first have the LangChain CLI and Pydantic installed in a Python virtual environment:

```
pip install -U langchain-cli pydantic==1.10.13
```

To create a new LangChain project and install this as the only package, you can do:

```
langchain app new my-app --package rag-redis
```

If you want to add this to an existing project, you can just run:

```
langchain app add rag-redis
```

And add the following code snippet to your `app/server.py` file:

```
from rag_redis.chain import chain as rag_redis_chainadd_routes(app, rag_redis_chain, path="/rag-redis")
```

(Optional) Let's now configure LangSmith. LangSmith will help us trace, monitor and debug LangChain applications. You can sign up for LangSmith [here](https://smith.langchain.com/). If you don't have access, you can skip this section

```
export LANGCHAIN_TRACING_V2=trueexport LANGCHAIN_API_KEY=<your-api-key>export LANGCHAIN_PROJECT=<your-project>  # if not specified, defaults to "default"
```

If you are inside this directory, then you can spin up a LangServe instance directly by:

This will start the FastAPI app with a server is running locally at [http://localhost:8000](http://localhost:8000/)

We can see all templates at [http://127.0.0.1:8000/docs](http://127.0.0.1:8000/docs) We can access the playground at [http://127.0.0.1:8000/rag-redis/playground](http://127.0.0.1:8000/rag-redis/playground)

We can access the template from code with:

```
from langserve.client import RemoteRunnablerunnable = RemoteRunnable("http://localhost:8000/rag-redis")
```
## rag-semi-structured

This template performs RAG on semi-structured data, such as a PDF with text and tables.

See [this cookbook](https://github.com/langchain-ai/langchain/blob/master/cookbook/Semi_Structured_RAG.ipynb) as a reference.

## Environment Setup[​](#environment-setup "Direct link to Environment Setup")

Set the `OPENAI_API_KEY` environment variable to access the OpenAI models.

This uses [Unstructured](https://unstructured-io.github.io/unstructured/) for PDF parsing, which requires some system-level package installations.

On Mac, you can install the necessary packages with the following:

```
brew install tesseract poppler
```

## Usage[​](#usage "Direct link to Usage")

To use this package, you should first have the LangChain CLI installed:

```
pip install -U langchain-cli
```

To create a new LangChain project and install this as the only package, you can do:

```
langchain app new my-app --package rag-semi-structured
```

If you want to add this to an existing project, you can just run:

```
langchain app add rag-semi-structured
```

And add the following code to your `server.py` file:

```
from rag_semi_structured import chain as rag_semi_structured_chainadd_routes(app, rag_semi_structured_chain, path="/rag-semi-structured")
```

(Optional) Let's now configure LangSmith. LangSmith will help us trace, monitor and debug LangChain applications. You can sign up for LangSmith [here](https://smith.langchain.com/). If you don't have access, you can skip this section

```
export LANGCHAIN_TRACING_V2=trueexport LANGCHAIN_API_KEY=<your-api-key>export LANGCHAIN_PROJECT=<your-project>  # if not specified, defaults to "default"
```

If you are inside this directory, then you can spin up a LangServe instance directly by:

This will start the FastAPI app with a server is running locally at [http://localhost:8000](http://localhost:8000/)

We can see all templates at [http://127.0.0.1:8000/docs](http://127.0.0.1:8000/docs) We can access the playground at [http://127.0.0.1:8000/rag-semi-structured/playground](http://127.0.0.1:8000/rag-semi-structured/playground)

We can access the template from code with:

```
from langserve.client import RemoteRunnablerunnable = RemoteRunnable("http://localhost:8000/rag-semi-structured")
```

For more details on how to connect to the template, refer to the Jupyter notebook `rag_semi_structured`.
## neo4j-cypher-ft

This template allows you to interact with a Neo4j graph database using natural language, leveraging OpenAI's LLM.

Its main function is to convert natural language questions into Cypher queries (the language used to query Neo4j databases), execute these queries, and provide natural language responses based on the query's results.

The package utilizes a full-text index for efficient mapping of text values to database entries, thereby enhancing the generation of accurate Cypher statements.

In the provided example, the full-text index is used to map names of people and movies from the user's query to corresponding database entries.

## Environment Setup[​](#environment-setup "Direct link to Environment Setup")

The following environment variables need to be set:

```
OPENAI_API_KEY=<YOUR_OPENAI_API_KEY>NEO4J_URI=<YOUR_NEO4J_URI>NEO4J_USERNAME=<YOUR_NEO4J_USERNAME>NEO4J_PASSWORD=<YOUR_NEO4J_PASSWORD>
```

Additionally, if you wish to populate the DB with some example data, you can run `python ingest.py`. This script will populate the database with sample movie data and create a full-text index named `entity`, which is used to map person and movies from user input to database values for precise Cypher statement generation.

## Usage[​](#usage "Direct link to Usage")

To use this package, you should first have the LangChain CLI installed:

```
pip install -U langchain-cli
```

To create a new LangChain project and install this as the only package, you can do:

```
langchain app new my-app --package neo4j-cypher-ft
```

If you want to add this to an existing project, you can just run:

```
langchain app add neo4j-cypher-ft
```

And add the following code to your `server.py` file:

```
from neo4j_cypher_ft import chain as neo4j_cypher_ft_chainadd_routes(app, neo4j_cypher_ft_chain, path="/neo4j-cypher-ft")
```

(Optional) Let's now configure LangSmith. LangSmith will help us trace, monitor and debug LangChain applications. You can sign up for LangSmith [here](https://smith.langchain.com/). If you don't have access, you can skip this section

```
export LANGCHAIN_TRACING_V2=trueexport LANGCHAIN_API_KEY=<your-api-key>export LANGCHAIN_PROJECT=<your-project>  # if not specified, defaults to "default"
```

If you are inside this directory, then you can spin up a LangServe instance directly by:

This will start the FastAPI app with a server running locally at [http://localhost:8000](http://localhost:8000/)

We can see all templates at [http://127.0.0.1:8000/docs](http://127.0.0.1:8000/docs) We can access the playground at [http://127.0.0.1:8000/neo4j-cypher-ft/playground](http://127.0.0.1:8000/neo4j-cypher-ft/playground)

We can access the template from code with:

```
from langserve.client import RemoteRunnablerunnable = RemoteRunnable("http://localhost:8000/neo4j-cypher-ft")
```
## rag-aws-bedrock

This template is designed to connect with the AWS Bedrock service, a managed server that offers a set of foundation models.

It primarily uses the `Anthropic Claude` for text generation and `Amazon Titan` for text embedding, and utilizes FAISS as the vectorstore.

For additional context on the RAG pipeline, refer to [this notebook](https://github.com/aws-samples/amazon-bedrock-workshop/blob/main/03_QuestionAnswering/01_qa_w_rag_claude.ipynb).

## Environment Setup[​](#environment-setup "Direct link to Environment Setup")

Before you can use this package, ensure that you have configured `boto3` to work with your AWS account.

For details on how to set up and configure `boto3`, visit [this page](https://boto3.amazonaws.com/v1/documentation/api/latest/guide/quickstart.html#configuration).

In addition, you need to install the `faiss-cpu` package to work with the FAISS vector store:

You should also set the following environment variables to reflect your AWS profile and region (if you're not using the `default` AWS profile and `us-east-1` region):

*   `AWS_DEFAULT_REGION`
*   `AWS_PROFILE`

## Usage[​](#usage "Direct link to Usage")

First, install the LangChain CLI:

```
pip install -U langchain-cli
```

To create a new LangChain project and install this as the only package:

```
langchain app new my-app --package rag-aws-bedrock
```

To add this package to an existing project:

```
langchain app add rag-aws-bedrock
```

Then add the following code to your `server.py` file:

```
from rag_aws_bedrock import chain as rag_aws_bedrock_chainadd_routes(app, rag_aws_bedrock_chain, path="/rag-aws-bedrock")
```

(Optional) If you have access to LangSmith, you can configure it to trace, monitor, and debug LangChain applications. If you don't have access, you can skip this section.

```
export LANGCHAIN_TRACING_V2=trueexport LANGCHAIN_API_KEY=<your-api-key>export LANGCHAIN_PROJECT=<your-project>  # if not specified, defaults to "default"
```

If you are inside this directory, you can spin up a LangServe instance directly by:

This will start the FastAPI app with a server running locally at [http://localhost:8000](http://localhost:8000/)

You can see all templates at [http://127.0.0.1:8000/docs](http://127.0.0.1:8000/docs) and access the playground at [http://127.0.0.1:8000/rag-aws-bedrock/playground](http://127.0.0.1:8000/rag-aws-bedrock/playground).

You can access the template from code with:

```
from langserve.client import RemoteRunnablerunnable = RemoteRunnable("http://localhost:8000/rag-aws-bedrock")
```
## rag-singlestoredb

This template performs RAG using SingleStoreDB and OpenAI.

## Environment Setup[​](#environment-setup "Direct link to Environment Setup")

This template uses SingleStoreDB as a vectorstore and requires that `SINGLESTOREDB_URL` is set. It should take the form `admin:password@svc-xxx.svc.singlestore.com:port/db_name`

Set the `OPENAI_API_KEY` environment variable to access the OpenAI models.

## Usage[​](#usage "Direct link to Usage")

To use this package, you should first have the LangChain CLI installed:

```
pip install -U langchain-cli
```

To create a new LangChain project and install this as the only package, you can do:

```
langchain app new my-app --package rag-singlestoredb
```

If you want to add this to an existing project, you can just run:

```
langchain app add rag-singlestoredb
```

And add the following code to your `server.py` file:

```
from rag_singlestoredb import chain as rag_singlestoredb_chainadd_routes(app, rag_singlestoredb_chain, path="/rag-singlestoredb")
```

(Optional) Let's now configure LangSmith. LangSmith will help us trace, monitor and debug LangChain applications. You can sign up for LangSmith [here](https://smith.langchain.com/). If you don't have access, you can skip this section

```
export LANGCHAIN_TRACING_V2=trueexport LANGCHAIN_API_KEY=<your-api-key>export LANGCHAIN_PROJECT=<your-project>  # if not specified, defaults to "default"
```

If you are inside this directory, then you can spin up a LangServe instance directly by:

This will start the FastAPI app with a server is running locally at [http://localhost:8000](http://localhost:8000/)

We can see all templates at [http://127.0.0.1:8000/docs](http://127.0.0.1:8000/docs) We can access the playground at [http://127.0.0.1:8000/rag-singlestoredb/playground](http://127.0.0.1:8000/rag-singlestoredb/playground)

We can access the template from code with:

```
from langserve.client import RemoteRunnablerunnable = RemoteRunnable("http://localhost:8000/rag-singlestoredb")
```

* * *

#### Help us out by providing feedback on this documentation page:
## rag-timescale-conversation

This template is used for [conversational](https://python.langchain.com/docs/expression_language/cookbook/retrieval#conversational-retrieval-chain) [retrieval](https://python.langchain.com/docs/use_cases/question_answering/), which is one of the most popular LLM use-cases.

It passes both a conversation history and retrieved documents into an LLM for synthesis.

## Environment Setup[​](#environment-setup "Direct link to Environment Setup")

This template uses Timescale Vector as a vectorstore and requires that `TIMESCALES_SERVICE_URL`. Signup for a 90-day trial [here](https://console.cloud.timescale.com/signup?utm_campaign=vectorlaunch&utm_source=langchain&utm_medium=referral) if you don't yet have an account.

To load the sample dataset, set `LOAD_SAMPLE_DATA=1`. To load your own dataset see the section below.

Set the `OPENAI_API_KEY` environment variable to access the OpenAI models.

## Usage[​](#usage "Direct link to Usage")

To use this package, you should first have the LangChain CLI installed:

```
pip install -U "langchain-cli[serve]"
```

To create a new LangChain project and install this as the only package, you can do:

```
langchain app new my-app --package rag-timescale-conversation
```

If you want to add this to an existing project, you can just run:

```
langchain app add rag-timescale-conversation
```

And add the following code to your `server.py` file:

```
from rag_timescale_conversation import chain as rag_timescale_conversation_chainadd_routes(app, rag_timescale_conversation_chain, path="/rag-timescale_conversation")
```

(Optional) Let's now configure LangSmith. LangSmith will help us trace, monitor and debug LangChain applications. You can sign up for LangSmith [here](https://smith.langchain.com/). If you don't have access, you can skip this section

```
export LANGCHAIN_TRACING_V2=trueexport LANGCHAIN_API_KEY=<your-api-key>export LANGCHAIN_PROJECT=<your-project>  # if not specified, defaults to "default"
```

If you are inside this directory, then you can spin up a LangServe instance directly by:

This will start the FastAPI app with a server is running locally at [http://localhost:8000](http://localhost:8000/)

We can see all templates at [http://127.0.0.1:8000/docs](http://127.0.0.1:8000/docs) We can access the playground at [http://127.0.0.1:8000/rag-timescale-conversation/playground](http://127.0.0.1:8000/rag-timescale-conversation/playground)

We can access the template from code with:

```
from langserve.client import RemoteRunnablerunnable = RemoteRunnable("http://localhost:8000/rag-timescale-conversation")
```

See the `rag_conversation.ipynb` notebook for example usage.

## Loading your own dataset[​](#loading-your-own-dataset "Direct link to Loading your own dataset")

To load your own dataset you will have to create a `load_dataset` function. You can see an example, in the `load_ts_git_dataset` function defined in the `load_sample_dataset.py` file. You can then run this as a standalone function (e.g. in a bash script) or add it to chain.py (but then you should run it just once).
## neo4j\_cypher

This template allows you to interact with a Neo4j graph database in natural language, using an OpenAI LLM.

It transforms a natural language question into a Cypher query (used to fetch data from Neo4j databases), executes the query, and provides a natural language response based on the query results.

## Environment Setup[​](#environment-setup "Direct link to Environment Setup")

Define the following environment variables:

```
OPENAI_API_KEY=<YOUR_OPENAI_API_KEY>NEO4J_URI=<YOUR_NEO4J_URI>NEO4J_USERNAME=<YOUR_NEO4J_USERNAME>NEO4J_PASSWORD=<YOUR_NEO4J_PASSWORD>
```

## Neo4j database setup[​](#neo4j-database-setup "Direct link to Neo4j database setup")

There are a number of ways to set up a Neo4j database.

### Neo4j Aura[​](#neo4j-aura "Direct link to Neo4j Aura")

Neo4j AuraDB is a fully managed cloud graph database service. Create a free instance on [Neo4j Aura](https://neo4j.com/cloud/platform/aura-graph-database?utm_source=langchain&utm_content=langserve). When you initiate a free database instance, you'll receive credentials to access the database.

## Populating with data[​](#populating-with-data "Direct link to Populating with data")

If you want to populate the DB with some example data, you can run `python ingest.py`. This script will populate the database with sample movie data.

## Usage[​](#usage "Direct link to Usage")

To use this package, you should first have the LangChain CLI installed:

```
pip install -U langchain-cli
```

To create a new LangChain project and install this as the only package, you can do:

```
langchain app new my-app --package neo4j-cypher
```

If you want to add this to an existing project, you can just run:

```
langchain app add neo4j-cypher
```

And add the following code to your `server.py` file:

```
from neo4j_cypher import chain as neo4j_cypher_chainadd_routes(app, neo4j_cypher_chain, path="/neo4j-cypher")
```

(Optional) Let's now configure LangSmith. LangSmith will help us trace, monitor and debug LangChain applications. You can sign up for LangSmith [here](https://smith.langchain.com/). If you don't have access, you can skip this section

```
export LANGCHAIN_TRACING_V2=trueexport LANGCHAIN_API_KEY=<your-api-key>export LANGCHAIN_PROJECT=<your-project>  # if not specified, defaults to "default"
```

If you are inside this directory, then you can spin up a LangServe instance directly by:

This will start the FastAPI app with a server is running locally at [http://localhost:8000](http://localhost:8000/)

We can see all templates at [http://127.0.0.1:8000/docs](http://127.0.0.1:8000/docs) We can access the playground at [http://127.0.0.1:8000/neo4j\_cypher/playground](http://127.0.0.1:8000/neo4j_cypher/playground)

We can access the template from code with:

```
from langserve.client import RemoteRunnablerunnable = RemoteRunnable("http://localhost:8000/neo4j-cypher")
```