Updating files

This commit is contained in:
William Fu-Hinthorn
2024-09-19 08:32:04 -07:00
parent 15771c3553
commit f52bfc1762
+87 -80
View File
@@ -14,13 +14,19 @@ It contains example graphs exported from `src/retrieval_agent/graph.ts` that imp
## What it does
The retrieval agent:
This project has two graphs: an "index" graph, and a "retrieval" graph.
The index graph takes in document objects and strings, and it indexes them for the configured `userId`.
```json
[{ "page_content": "I have 1 cat." }]
```
The retrieval chat bot manages a chat history and responds based on fetched context. It:
1. Takes a user **query** as input
2. Generates a search query based on the conversation history (if not the first turn)
3. Retrieves relevant documents from an indexed knowledge base
4. Formulates a response using the retrieved information and conversation context
5. Returns the generated answer to the user
2. Searches for documents in filtered by userId based on the conversation history
3. Responds using the retrieved information and conversation context
By default, it's set up to answer questions based on the user's indexed documents, which are filtered by the user's ID for personalized responses.
@@ -40,9 +46,9 @@ Assuming you have already [installed LangGraph Studio](https://github.com/langch
Setup instruction auto-generated by `langgraph template lock`. DO NOT EDIT MANUALLY.
-->
<details>
<summary>Setup for `retrieverProvider`</summary>
The `retriever` configuration defaults are shown below:
### Setup Retriever
The defaults values for `retrieverProvider` are shown below:
```yaml
retrieverProvider: elastic
@@ -50,9 +56,9 @@ retrieverProvider: elastic
Follow the instructions below to get set up, or pick one of the additional options.
### Setup Elasticsearch
#### Setup Elasticsearch
#### Elastic Cloud
**Elastic Cloud**
1. Signup for a free trial with [Elastic Cloud](https://cloud.elastic.co/registration?onboarding_token=search&cta=cloud-registration&tech=trial&plcmt=article%20content&pg=langchain).
2. Get the Elasticsearch URL, found under Applications of your deployment.
@@ -64,7 +70,7 @@ ELASTICSEARCH_URL=<ES_URL>
ELASTICSEARCH_API_KEY=<API_KEY>
```
#### Local Elasticsearch (Docker)
**Local Elasticsearch (Docker)**
```
docker run -p 127.0.0.1:9200:9200 -d --name elasticsearch --network elastic-net -e ELASTIC_PASSWORD=changeme -e "discovery.type=single-node" -e "xpack.security.http.ssl.enabled=false" -e "xpack.license.self_generated.type=trial" docker.elastic.co/elasticsearch/elasticsearch:8.15.1
@@ -82,7 +88,56 @@ ELASTICSEARCH_USER=elastic
ELASTICSEARCH_PASSWORD=changeme
```
### Pinecone Serverless
#### MongoDB Atlas
MongoDB Atlas is a fully-managed cloud database that includes vector search capabilities for AI-powered applications.
1. Create a free Atlas cluster:
- Go to the [MongoDB Atlas website](https://www.mongodb.com/cloud/atlas/register) and sign up for a free account.
- After logging in, create a free cluster by following the on-screen instructions.
2. Create a vector search index
- Follow the instructions at [the Mongo docs](https://www.mongodb.com/docs/atlas/atlas-vector-search/vector-search-type/)
- By default, we use the collection `langgraph_retrieval_agent.default` - create the index there
- Add an indexed filter for path `user_id`
- **IMPORTANT**: select Atlas Vector Search NOT Atlas Search when creating the index
Your final JSON editor configuration should look something like the following:
```json
{
"fields": [
{
"numDimensions": 1536,
"path": "embedding",
"similarity": "cosine",
"type": "vector"
},
{
"path": "user_id",
"type": "filter"
}
]
}
```
The exact numDimensions may differ if you select a different embedding model.
2. Set up your environment:
- In the Atlas dashboard, click on "Connect" for your cluster.
- Choose "Connect your application" and copy the provided connection string.
- Create a `.env` file in your project root if you haven't already.
- Add your MongoDB Atlas connection string to the `.env` file:
```
MONGODB_URI="mongodb+srv://username:password@your-cluster-url.mongodb.net/?retryWrites=true&w=majority&appName=your-cluster-name"
```
Replace `username`, `password`, `your-cluster-url`, and `your-cluster-name` with your actual credentials and cluster information.
#### Pinecone Serverless
Pinecone is a managed, cloud-native vector database that provides long-term memory for high-performance AI applications.
@@ -105,54 +160,9 @@ PINECONE_API_KEY=your-api-key
PINECONE_INDEX_NAME=your-index-name
```
### MongoDB Atlas
### Setup Model
MongoDB Atlas is a fully-managed cloud database that includes vector search capabilities for AI-powered applications.
1. Create a free Atlas cluster:
- Go to the [MongoDB Atlas website](https://www.mongodb.com/cloud/atlas/register) and sign up for a free account.
- After logging in, create a free cluster by following the on-screen instructions.
2. Set up your environment:
- In the Atlas dashboard, click on "Connect" for your cluster.
- Choose "Connect your application" and copy the provided connection string.
- Create a `.env` file in your project root if you haven't already.
- Add your MongoDB Atlas connection string to the `.env` file:
```
MONGODB_URI="mongodb+srv://username:password@your-cluster-url.mongodb.net/?retryWrites=true&w=majority&appName=your-cluster-name"
```
Replace `username`, `password`, `your-cluster-url`, and `your-cluster-name` with your actual credentials and cluster information.
3. Set up a vector search index. After configuring your cluster, youll need to create an index on the collection field you want to search over.
Switch to the Atlas Search tab and click Create Search Index. From there, make sure you select Atlas Vector Search - JSON Editor, then select the appropriate database and collection and paste the following into the textbox:
```json
{
"fields": [
{
"numDimensions": 1536,
"path": "embedding",
"similarity": "euclidean",
"type": "vector"
}
]
}
```
Note that the dimensions property should match the dimensionality of the embeddings you are using. For example, Cohere embeddings have 1024 dimensions, and by default OpenAI embeddings have 1536.
[See this page](https://js.langchain.com/docs/integrations/vectorstores/mongodb_atlas/#setup) for more detailed information.
</details>
<details>
<summary>Setup for `responseModel` and `queryModel`</summary>
The `llm` configuration defaults are shown below:
The defaults values for `responseModel`, `queryModel` are shown below:
```yaml
responseModel: anthropic/claude-3-5-sonnet-20240620
@@ -161,7 +171,7 @@ queryModel: anthropic/claude-3-haiku-20240307
Follow the instructions below to get set up, or pick one of the additional options.
### Anthropic Chat Models
#### Anthropic
To use Anthropic's chat models:
@@ -172,18 +182,7 @@ To use Anthropic's chat models:
ANTHROPIC_API_KEY=your-api-key
```
### Fireworks Chat Models
To use Fireworks AI's chat models:
1. Sign up for a [Fireworks AI account](https://app.fireworks.ai/signup) and obtain an API key.
2. Add your Fireworks AI API key to your `.env` file:
```
FIREWORKS_API_KEY=your-api-key
```
#### OpenAI Chat Models
#### OpenAI
To use OpenAI's chat models:
@@ -194,11 +193,9 @@ To use OpenAI's chat models:
OPENAI_API_KEY=your-api-key
```
</details>
### Setup Embedding Model
<details>
<summary>Setup for `embeddingModel`</summary>
The `embeddings` configuration defaults are shown below:
The defaults values for `embeddingModel` are shown below:
```yaml
embeddingModel: openai/text-embedding-3-small
@@ -206,7 +203,7 @@ embeddingModel: openai/text-embedding-3-small
Follow the instructions below to get set up, or pick one of the additional options.
#### OpenAI Embeddings
#### OpenAI
To use OpenAI's embeddings:
@@ -217,7 +214,7 @@ To use OpenAI's embeddings:
OPENAI_API_KEY=your-api-key
```
#### Cohere Embeddings
#### Cohere
To use Cohere's embeddings:
@@ -228,12 +225,22 @@ To use Cohere's embeddings:
COHERE_API_KEY=your-api-key
```
</details>
<!--
End setup instructions
-->
## Using
Once you've set up your retriever saved your model secrets, it's time to try it out! First, let's add some information to the index. Open studio, select the "indexer" graph from the dropdown in the top-left, provide an example user ID in the configuration at the bottom, and then add some content to chat over.
```json
[{ "page_content": "My cat knows python." }]
```
When you upload content, it will be indexed under the configured user ID. You know it's complete when the indexer "delete"'s the content from its graph memory (since it's been persisted in your configured storage provider).
Next, open the "retrieval_graph" using the dropdown in the top-left. Ask it about your cat to confirm it can fetch the required information! If you change the `userId` at any time, notice how it no longer has access to your information. The graph is doing simple filtering of content so you only access the information under the provided ID.
## How to customize
You can customize this retrieval agent template in several ways: