Although this might sound like another way to make money on LLM API calls...
text
Although this might sound like another way to make money on LLM API calls...
new_line
new_line
Good folks at 
text
Good folks at 
@AnthropicAI
mention
AnthropicAI
 just introduced Contextual Retrieval, and it's a significant yet logical step up from simple Retrieval-Augmented Generation (RAG)!
text
 just introduced Contextual Retrieval, and it's a significant yet logical step up from simple Retrieval-Augmented Generation (RAG)!
new_line
new_line
Here are the steps to implement Contextual Retrieval based on Anthropic's approach:
text
Here are the steps to implement Contextual Retrieval based on Anthropic's approach:
new_line
new_line
1. Preprocess the knowledge base:
text
1. Preprocess the knowledge base:
new_line
   - Break down documents into smaller chunks (typically a few hundred tokens each).
text
   - Break down documents into smaller chunks (typically a few hundred tokens each).
new_line
   - Generate contextual information for each chunk using Claude 3 Haiku with a specific prompt.
text
   - Generate contextual information for each chunk using Claude 3 Haiku with a specific prompt.
new_line
   - Prepend the generated context (usually 50-100 tokens) to each chunk.
text
   - Prepend the generated context (usually 50-100 tokens) to each chunk.
new_line
new_line
2. Create embeddings and a BM25 index:
text
2. Create embeddings and a BM25 index:
new_line
   - Use an embedding model (Gemini or Voyage recommended) to convert contextualized chunks into vector embeddings.
text
   - Use an embedding model (Gemini or Voyage recommended) to convert contextualized chunks into vector embeddings.
new_line
   - Create a BM25 index using the contextualized chunks.
text
   - Create a BM25 index using the contextualized chunks.
new_line
new_line
3. Set up the retrieval process:
text
3. Set up the retrieval process:
new_line
   - Implement a system to search both the vector embeddings and the BM25 index.
text
   - Implement a system to search both the vector embeddings and the BM25 index.
new_line
   - Use rank fusion techniques to combine and deduplicate results from both searches.
text
   - Use rank fusion techniques to combine and deduplicate results from both searches.
new_line
new_line
4. Implement reranking (optional but recommended):
text
4. Implement reranking (optional but recommended):
new_line
   - Retrieve the top 150 potentially relevant chunks initially.
text
   - Retrieve the top 150 potentially relevant chunks initially.
new_line
   - Use a reranking model (e.g., Cohere reranker) to score these chunks based on relevance to the query.
text
   - Use a reranking model (e.g., Cohere reranker) to score these chunks based on relevance to the query.
new_line
   - Select the top 20 chunks after reranking.
text
   - Select the top 20 chunks after reranking.
new_line
new_line
5. Integrate with the generative model:
text
5. Integrate with the generative model:
new_line
   - Add the top 20 chunks (or top K, based on your specific needs) to the prompt sent to the generative model.
text
   - Add the top 20 chunks (or top K, based on your specific needs) to the prompt sent to the generative model.
new_line
new_line
6. Optimize for your use case:
text
6. Optimize for your use case:
new_line
   - Experiment with chunk sizes, boundary selection, and overlap.
text
   - Experiment with chunk sizes, boundary selection, and overlap.
new_line
   - Consider creating custom contextualizer prompts for your specific domain.
text
   - Consider creating custom contextualizer prompts for your specific domain.
new_line
   - Test different numbers of retrieved chunks (5, 10, 20) to find the optimal balance.
text
   - Test different numbers of retrieved chunks (5, 10, 20) to find the optimal balance.
new_line
new_line
7. Leverage prompt caching:
text
7. Leverage prompt caching:
new_line
   - Use Claude's prompt caching feature to reduce costs when generating contextualized chunks.
text
   - Use Claude's prompt caching feature to reduce costs when generating contextualized chunks.
new_line
   - Cache the reference document once and reference it for each chunk, rather than passing it repeatedly.
text
   - Cache the reference document once and reference it for each chunk, rather than passing it repeatedly.
new_line
new_line
8. Evaluate and iterate
text
8. Evaluate and iterate
Although this might sound like another way to make money on LLM API calls...

Good folks at @AnthropicAI just introduced Contextual Retrieval, and it's a significant yet logical step up from simple Retrieval-Augmented Generation (RAG)!

Here are the steps to implement Contextual Retrieval based on Anthropic's approach:

1. Preprocess the knowledge base:
   - Break down documents into smaller chunks (typically a few hundred tokens each).
   - Generate contextual information for each chunk using Claude 3 Haiku with a specific prompt.
   - Prepend the generated context (usually 50-100 tokens) to each chunk.

2. Create embeddings and a BM25 index:
   - Use an embedding model (Gemini or Voyage recommended) to convert contextualized chunks into vector embeddings.
   - Create a BM25 index using the contextualized chunks.

3. Set up the retrieval process:
   - Implement a system to search both the vector embeddings and the BM25 index.
   - Use rank fusion techniques to combine and deduplicate results from both searches.

4. Implement reranking (optional but recommended):
   - Retrieve the top 150 potentially relevant chunks initially.
   - Use a reranking model (e.g., Cohere reranker) to score these chunks based on relevance to the query.
   - Select the top 20 chunks after reranking.

5. Integrate with the generative model:
   - Add the top 20 chunks (or top K, based on your specific needs) to the prompt sent to the generative model.

6. Optimize for your use case:
   - Experiment with chunk sizes, boundary selection, and overlap.
   - Consider creating custom contextualizer prompts for your specific domain.
   - Test different numbers of retrieved chunks (5, 10, 20) to find the optimal balance.

7. Leverage prompt caching:
   - Use Claude's prompt caching feature to reduce costs when generating contextualized chunks.
   - Cache the reference document once and reference it for each chunk, rather than passing it repeatedly.

8. Evaluate and iterate
👀
John6666 KingNish clem victor louisbrulenaudet
🔥
badamczewski01 mathiasn1