seansullivan/Langchain-Docs huggingface dataset:
## cassandra-synonym-caching

This template provides a simple chain template showcasing the usage of LLM Caching backed by Apache Cassandra® or Astra DB through CQL.

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

To set up your environment, you will need the following:

*   an [Astra](https://astra.datastax.com/) Vector Database (free tier is fine!). **You need a [Database Administrator token](https://awesome-astra.github.io/docs/pages/astra/create-token/#c-procedure)**, in particular the string starting with `AstraCS:...`;
*   likewise, get your [Database ID](https://awesome-astra.github.io/docs/pages/astra/faq/#where-should-i-find-a-database-identifier) ready, you will have to enter it below;
*   an **OpenAI API Key**. (More info [here](https://cassio.org/start_here/#llm-access), note that out-of-the-box this demo supports OpenAI unless you tinker with the code.)

_Note:_ you can alternatively use a regular Cassandra cluster: to do so, make sure you provide the `USE_CASSANDRA_CLUSTER` entry as shown in `.env.template` and the subsequent environment variables to specify how to connect to it.

## 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 cassandra-synonym-caching
```

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

```
langchain app add cassandra-synonym-caching
```

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

```
from cassandra_synonym_caching import chain as cassandra_synonym_caching_chainadd_routes(app, cassandra_synonym_caching_chain, path="/cassandra-synonym-caching")
```

(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/cassandra-synonym-caching/playground](http://127.0.0.1:8000/cassandra-synonym-caching/playground)

We can access the template from code with:

```
from langserve.client import RemoteRunnablerunnable = RemoteRunnable("http://localhost:8000/cassandra-synonym-caching")
```

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

Stand-alone LangServe template repo: [here](https://github.com/hemidactylus/langserve_cassandra_synonym_caching).
## cassandra-entomology-rag

This template will perform RAG using Apache Cassandra® or Astra DB through CQL (`Cassandra` vector store class)

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

For the setup, you will require:

*   an [Astra](https://astra.datastax.com/) Vector Database. You must have a [Database Administrator token](https://awesome-astra.github.io/docs/pages/astra/create-token/#c-procedure), specifically the string starting with `AstraCS:...`.
*   [Database ID](https://awesome-astra.github.io/docs/pages/astra/faq/#where-should-i-find-a-database-identifier).
*   an **OpenAI API Key**. (More info [here](https://cassio.org/start_here/#llm-access))

You may also use a regular Cassandra cluster. In this case, provide the `USE_CASSANDRA_CLUSTER` entry as shown in `.env.template` and the subsequent environment variables to specify how to connect to it.

The connection parameters and secrets must be provided through environment variables. Refer to `.env.template` for the required variables.

## 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 cassandra-entomology-rag
```

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

```
langchain app add cassandra-entomology-rag
```

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

```
from cassandra_entomology_rag import chain as cassandra_entomology_rag_chainadd_routes(app, cassandra_entomology_rag_chain, path="/cassandra-entomology-rag")
```

(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/cassandra-entomology-rag/playground](http://127.0.0.1:8000/cassandra-entomology-rag/playground)

We can access the template from code with:

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

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

Stand-alone repo with LangServe chain: [here](https://github.com/hemidactylus/langserve_cassandra_entomology_rag).
## rag-momento-vector-index

This template performs RAG using Momento Vector Index (MVI) and OpenAI.

> MVI: the most productive, easiest to use, serverless vector index for your data. To get started with MVI, simply sign up for an account. There's no need to handle infrastructure, manage servers, or be concerned about scaling. MVI is a service that scales automatically to meet your needs. Combine with other Momento services such as Momento Cache to cache prompts and as a session store or Momento Topics as a pub/sub system to broadcast events to your application.

To sign up and access MVI, visit the [Momento Console](https://console.gomomento.com/).

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

This template uses Momento Vector Index as a vectorstore and requires that `MOMENTO_API_KEY`, and `MOMENTO_INDEX_NAME` are set.

Go to the [console](https://console.gomomento.com/) to get an API key.

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-momento-vector-index
```

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

```
langchain app add rag-momento-vector-index
```

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

```
from rag_momento_vector_index import chain as rag_momento_vector_index_chainadd_routes(app, rag_momento_vector_index_chain, path="/rag-momento-vector-index")
```

(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-momento-vector-index/playground](http://127.0.0.1:8000/rag-momento-vector-index/playground)

We can access the template from code with:

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

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

We have included a sample module to index data. That is available at `rag_momento_vector_index/ingest.py`. You will see a commented out line in `chain.py` that invokes this. Uncomment to use.
## rag-matching-engine

This template performs RAG using Google Cloud Platform's Vertex AI with the matching engine.

It will utilize a previously created index to retrieve relevant documents or contexts based on user-provided questions.

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

An index should be created before running the code.

The process to create this index can be found [here](https://github.com/GoogleCloudPlatform/generative-ai/blob/main/language/use-cases/document-qa/question_answering_documents_langchain_matching_engine.ipynb).

Environment variables for Vertex should be set:

```
PROJECT_IDME_REGIONGCS_BUCKETME_INDEX_IDME_ENDPOINT_ID
```

## 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-matching-engine
```

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

```
langchain app add rag-matching-engine
```

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

```
from rag_matching_engine import chain as rag_matching_engine_chainadd_routes(app, rag_matching_engine_chain, path="/rag-matching-engine")
```

(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-matching-engine/playground](http://127.0.0.1:8000/rag-matching-engine/playground)

We can access the template from code with:

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

For more details on how to connect to the template, refer to the Jupyter notebook `rag_matching_engine`.
## Chain-of-Note (Wikipedia)

Implements Chain-of-Note as described in [https://arxiv.org/pdf/2311.09210.pdf](https://arxiv.org/pdf/2311.09210.pdf) by Yu, et al. Uses Wikipedia for retrieval.

Check out the prompt being used here [https://smith.langchain.com/hub/bagatur/chain-of-note-wiki](https://smith.langchain.com/hub/bagatur/chain-of-note-wiki).

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

Uses Anthropic claude-3-sonnet-20240229 chat model. Set Anthropic API key:

```
export ANTHROPIC_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[serve]"
```

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

```
langchain app new my-app --package chain-of-note-wiki
```

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

```
langchain app add chain-of-note-wiki
```

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

```
from chain_of_note_wiki import chain as chain_of_note_wiki_chainadd_routes(app, chain_of_note_wiki_chain, path="/chain-of-note-wiki")
```

(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/chain-of-note-wiki/playground](http://127.0.0.1:8000/chain-of-note-wiki/playground)

We can access the template from code with:

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

* * *

#### Help us out by providing feedback on this documentation page:
## cohere-librarian

This template turns Cohere into a librarian.

It demonstrates the use of a router to switch between chains that can handle different things: a vector database with Cohere embeddings; a chat bot that has a prompt with some information about the library; and finally a RAG chatbot that has access to the internet.

For a fuller demo of the book recomendation, consider replacing books\_with\_blurbs.csv with a larger sample from the following dataset: [https://www.kaggle.com/datasets/jdobrow/57000-books-with-metadata-and-blurbs/](https://www.kaggle.com/datasets/jdobrow/57000-books-with-metadata-and-blurbs/) .

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

Set the `COHERE_API_KEY` environment variable to access the Cohere 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 cohere-librarian
```

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

```
langchain app add cohere-librarian
```

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

```
from cohere_librarian.chain import chain as cohere_librarian_chainadd_routes(app, cohere_librarian_chain, path="/cohere-librarian")
```

(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://localhost:8000/docs](http://localhost:8000/docs) We can access the playground at [http://localhost:8000/cohere-librarian/playground](http://localhost:8000/cohere-librarian/playground)

We can access the template from code with:

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

* * *

#### Help us out by providing feedback on this documentation page:
A QA application that queries multiple domain-specific retrievers and selects the most relevant documents from across all retrieved results.

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

This application queries PubMed, ArXiv, Wikipedia, and [Kay AI](https://www.kay.ai/) (for SEC filings).

You will need to create a free Kay AI account and [get your API key here](https://www.kay.ai/). Then set environment variable:

```
export KAY_API_KEY="<YOUR_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 rag-multi-index-fusion
```

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

```
langchain app add rag-multi-index-fusion
```

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

```
from rag_multi_index_fusion import chain as rag_multi_index_fusion_chainadd_routes(app, rag_multi_index_fusion_chain, path="/rag-multi-index-fusion")
```

(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-multi-index-fusion/playground](http://127.0.0.1:8000/rag-multi-index-fusion/playground)

We can access the template from code with:

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

* * *

#### Help us out by providing feedback on this documentation page:
## csv-agent

This template uses a [csv agent](https://python.langchain.com/docs/integrations/toolkits/csv) with tools (Python REPL) and memory (vectorstore) for interaction (question-answering) with text data.

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

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

To set up the environment, the `ingest.py` script should be run to handle the ingestion into a vectorstore.

## 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 csv-agent
```

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

```
langchain app add csv-agent
```

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

```
from csv_agent.agent import agent_executor as csv_agent_chainadd_routes(app, csv_agent_chain, path="/csv-agent")
```

(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/csv-agent/playground](http://127.0.0.1:8000/csv-agent/playground)

We can access the template from code with:

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

* * *

#### Help us out by providing feedback on this documentation page:
A QA application that routes between different domain-specific retrievers given a user question.

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

This application queries PubMed, ArXiv, Wikipedia, and [Kay AI](https://www.kay.ai/) (for SEC filings).

You will need to create a free Kay AI account and [get your API key here](https://www.kay.ai/). Then set environment variable:

```
export KAY_API_KEY="<YOUR_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 rag-multi-index-router
```

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

```
langchain app add rag-multi-index-router
```

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

```
from rag_multi_index_router import chain as rag_multi_index_router_chainadd_routes(app, rag_multi_index_router_chain, path="/rag-multi-index-router")
```

(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-multi-index-router/playground](http://127.0.0.1:8000/rag-multi-index-router/playground)

We can access the template from code with:

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

* * *

#### Help us out by providing feedback on this documentation page:
## elastic-query-generator

This template allows interacting with Elasticsearch analytics databases in natural language using LLMs.

It builds search queries via the Elasticsearch DSL API (filters and aggregations).

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

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

### Installing Elasticsearch[​](#installing-elasticsearch "Direct link to Installing Elasticsearch")

There are a number of ways to run Elasticsearch. However, one recommended way is through Elastic Cloud.

Create a free trial account on [Elastic Cloud](https://cloud.elastic.co/registration?utm_source=langchain&utm_content=langserve).

With a deployment, update the connection string.

Password and connection (elasticsearch url) can be found on the deployment console.

Note that the Elasticsearch client must have permissions for index listing, mapping description, and search queries.

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

If you want to populate the DB with some example info, you can run `python ingest.py`.

This will create a `customers` index. In this package, we specify indexes to generate queries against, and we specify `["customers"]`. This is specific to setting up your Elastic index.

## 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 elastic-query-generator
```

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

```
langchain app add elastic-query-generator
```

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

```
from elastic_query_generator.chain import chain as elastic_query_generator_chainadd_routes(app, elastic_query_generator_chain, path="/elastic-query-generator")
```

(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/elastic-query-generator/playground](http://127.0.0.1:8000/elastic-query-generator/playground)

We can access the template from code with:

```
from langserve.client import RemoteRunnablerunnable = RemoteRunnable("http://localhost:8000/elastic-query-generator")
```
## extraction-anthropic-functions

This template enables [Anthropic function calling](https://python.langchain.com/docs/integrations/chat/anthropic_functions).

This can be used for various tasks, such as extraction or tagging.

The function output schema can be set in `chain.py`.

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

Set the `ANTHROPIC_API_KEY` environment variable to access the Anthropic 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 extraction-anthropic-functions
```

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

```
langchain app add extraction-anthropic-functions
```

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

```
from extraction_anthropic_functions import chain as extraction_anthropic_functions_chainadd_routes(app, extraction_anthropic_functions_chain, path="/extraction-anthropic-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/extraction-anthropic-functions/playground](http://127.0.0.1:8000/extraction-anthropic-functions/playground)

We can access the template from code with:

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

By default, the package will extract the title and author of papers from the information you specify in `chain.py`. This template will use `Claude2` by default.

* * *
## openai-functions-agent

This template creates an agent that uses OpenAI function calling to communicate its decisions on what actions to take.

This example creates an agent that can optionally look up information on the internet using Tavily's search engine.

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

The following environment variables need to be set:

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

Set the `TAVILY_API_KEY` environment variable to access Tavily.

## 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 openai-functions-agent
```

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

```
langchain app add openai-functions-agent
```

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

```
from openai_functions_agent import agent_executor as openai_functions_agent_chainadd_routes(app, openai_functions_agent_chain, path="/openai-functions-agent")
```

(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/openai-functions-agent/playground](http://127.0.0.1:8000/openai-functions-agent/playground)

We can access the template from code with:

```
from langserve.client import RemoteRunnablerunnable = RemoteRunnable("http://localhost:8000/openai-functions-agent")
```
## rag-ollama-multi-query

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

The multi-query retriever is an example of query transformation, generating 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.

We use a private, local LLM for the narrow task of query generation to avoid excessive calls to a larger LLM API.

See an example trace for Ollama LLM performing the query expansion [here](https://smith.langchain.com/public/8017d04d-2045-4089-b47f-f2d66393a999/r).

But we use OpenAI for the more challenging task of answer syntesis (full trace example [here](https://smith.langchain.com/public/ec75793b-645b-498d-b855-e8d85e1f6738/r)).

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

To set up the environment, you need to download Ollama.

Follow the instructions [here](https://python.langchain.com/docs/integrations/chat/ollama).

You can choose the desired LLM with Ollama.

This template uses `zephyr`, which can be accessed using `ollama pull zephyr`.

There are many other options available [here](https://ollama.ai/library).

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-ollama-multi-query
```

To add this package to an existing project, run:

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

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

```
from rag_ollama_multi_query import chain as rag_ollama_multi_query_chainadd_routes(app, rag_ollama_multi_query_chain, path="/rag-ollama-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-ollama-multi-query/playground](http://127.0.0.1:8000/rag-ollama-multi-query/playground)

To access the template from code, use:

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

This Template performs RAG using [OpenSearch](https://python.langchain.com/docs/integrations/vectorstores/opensearch).

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

Set the following environment variables.

*   `OPENAI_API_KEY` - To access OpenAI Embeddings and Models.

And optionally set the OpenSearch ones if not using defaults:

*   `OPENSEARCH_URL` - URL of the hosted OpenSearch Instance
*   `OPENSEARCH_USERNAME` - User name for the OpenSearch instance
*   `OPENSEARCH_PASSWORD` - Password for the OpenSearch instance
*   `OPENSEARCH_INDEX_NAME` - Name of the index

To run the default OpenSeach instance in docker, you can use the command

```
docker run -p 9200:9200 -p 9600:9600 -e "discovery.type=single-node" --name opensearch-node -d opensearchproject/opensearch:latest
```

Note: To load dummy index named `langchain-test` with dummy documents, run `python dummy_index_setup.py` in the package

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

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

```
langchain app add rag-opensearch
```

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

```
from rag_opensearch import chain as rag_opensearch_chainadd_routes(app, rag_opensearch_chain, path="/rag-opensearch")
```

(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-opensearch/playground](http://127.0.0.1:8000/rag-opensearch/playground)

We can access the template from code with:

```
from langserve.client import RemoteRunnablerunnable = RemoteRunnable("http://localhost:8000/rag-opensearch")
```
## gemini-functions-agent

This template creates an agent that uses Google Gemini function calling to communicate its decisions on what actions to take.

This example creates an agent that can optionally look up information on the internet using Tavily's search engine.

[See an example LangSmith trace here](https://smith.langchain.com/public/0ebf1bd6-b048-4019-b4de-25efe8d3d18c/r)

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

The following environment variables need to be set:

Set the `TAVILY_API_KEY` environment variable to access Tavily

Set the `GOOGLE_API_KEY` environment variable to access the Google Gemini APIs.

## 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 gemini-functions-agent
```

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

```
langchain app add gemini-functions-agent
```

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

```
from gemini_functions_agent import agent_executor as gemini_functions_agent_chainadd_routes(app, gemini_functions_agent_chain, path="/openai-functions-agent")
```

(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/gemini-functions-agent/playground](http://127.0.0.1:8000/gemini-functions-agent/playground)

We can access the template from code with:

```
from langserve.client import RemoteRunnablerunnable = RemoteRunnable("http://localhost:8000/gemini-functions-agent")
```
## openai-functions-tool-retrieval-agent

The novel idea introduced in this template is the idea of using retrieval to select the set of tools to use to answer an agent query. This is useful when you have many many tools to select from. You cannot put the description of all the tools in the prompt (because of context length issues) so instead you dynamically select the N tools you do want to consider using at run time.

In this template we will create a somewhat contrived example. We will have one legitimate tool (search) and then 99 fake tools which are just nonsense. We will then add a step in the prompt template that takes the user input and retrieves tool relevant to the query.

This template is based on [this Agent How-To](https://python.langchain.com/docs/modules/agents/how_to/custom_agent_with_tool_retrieval).

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

The following environment variables need to be set:

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

Set the `TAVILY_API_KEY` environment variable to access Tavily.

## 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 openai-functions-tool-retrieval-agent
```

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

```
langchain app add openai-functions-tool-retrieval-agent
```

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

```
from openai_functions_tool_retrieval_agent import agent_executor as openai_functions_tool_retrieval_agent_chainadd_routes(app, openai_functions_tool_retrieval_agent_chain, path="/openai-functions-tool-retrieval-agent")
```

(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/openai-functions-tool-retrieval-agent/playground](http://127.0.0.1:8000/openai-functions-tool-retrieval-agent/playground)

We can access the template from code with:

```
from langserve.client import RemoteRunnablerunnable = RemoteRunnable("http://localhost:8000/openai-functions-tool-retrieval-agent")
```
## extraction-openai-functions

This template uses [OpenAI function calling](https://python.langchain.com/docs/modules/chains/how_to/openai_functions) for extraction of structured output from unstructured input text.

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

## 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 extraction-openai-functions
```

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

```
langchain app add extraction-openai-functions
```

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

```
from extraction_openai_functions import chain as extraction_openai_functions_chainadd_routes(app, extraction_openai_functions_chain, path="/extraction-openai-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/extraction-openai-functions/playground](http://127.0.0.1:8000/extraction-openai-functions/playground)

We can access the template from code with:

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

By default, this package is set to extract the title and author of papers, as specified in the `chain.py` file.

LLM is leveraged by the OpenAI function by default.
## guardrails-output-parser

This template uses [guardrails-ai](https://github.com/guardrails-ai/guardrails) to validate LLM output.

The `GuardrailsOutputParser` is set in `chain.py`.

The default example protects against profanity.

## 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 guardrails-output-parser
```

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

```
langchain app add guardrails-output-parser
```

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

```
from guardrails_output_parser.chain import chain as guardrails_output_parser_chainadd_routes(app, guardrails_output_parser_chain, path="/guardrails-output-parser")
```

(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/guardrails-output-parser/playground](http://127.0.0.1:8000/guardrails-output-parser/playground)

We can access the template from code with:

```
from langserve.client import RemoteRunnablerunnable = RemoteRunnable("http://localhost:8000/guardrails-output-parser")
```

If Guardrails does not find any profanity, then the translated output is returned as is. If Guardrails does find profanity, then an empty string is returned.
## pii-protected-chatbot

This template creates a chatbot that flags any incoming PII and doesn't pass it to the LLM.

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

The following environment variables need to be 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[serve]"
```

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

```
langchain app new my-app --package pii-protected-chatbot
```

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

```
langchain app add pii-protected-chatbot
```

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

```
from pii_protected_chatbot.chain import chain as pii_protected_chatbotadd_routes(app, pii_protected_chatbot, path="/openai-functions-agent")
```

(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/pii\_protected\_chatbot/playground](http://127.0.0.1:8000/pii_protected_chatbot/playground)

We can access the template from code with:

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

* * *

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