Skip to content

Commit

Permalink
Adding a reranking section
Browse files Browse the repository at this point in the history
  • Loading branch information
ajosh0504 committed Jul 17, 2024
1 parent b8beaea commit f9bbd5a
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 10 deletions.
31 changes: 31 additions & 0 deletions docs/70-build-rag-app/3-add-reranking.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# 🦹 Re-rank retrieved results

Re-rankers are specialized models that are trained to calculate the relevance between query-document pairs. Without re-ranking the order of retrieved results is governed by the embedding model, which isn't optimized for relevance and can lead to poor LLM recall in RAG applications.

Fill in any `<CODE_BLOCK_N>` placeholders and run the cells under the **🦹‍♀️ Re-rank retrieved results** section in the notebook to add a re-ranking stage to the RAG application.

The answers for code blocks in this section are as follows:

**CODE_BLOCK_25**

<details>
<summary>Answer</summary>
<div>
```python
rerank_model.rank(
user_query, documents, return_documents=True, top_k=5
)
```
</div>
</details>

**CODE_BLOCK_26**

<details>
<summary>Answer</summary>
<div>
```python
"\n\n".join([d.get("text", "") for d in reranked_documents])
```
</div>
</details>
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Fill in any `<CODE_BLOCK_N>` placeholders and run the cells under the **🦹‍

The answers for code blocks in this section are as follows:

**CODE_BLOCK_25**
**CODE_BLOCK_27**

<details>
<summary>Answer</summary>
Expand All @@ -27,7 +27,7 @@ fw_client.chat.completions.create(
</div>
</details>

**CODE_BLOCK_26**
**CODE_BLOCK_28**

<details>
<summary>Answer</summary>
Expand Down
16 changes: 8 additions & 8 deletions docs/80-add-memory/2-add-memory.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Fill in any `<CODE_BLOCK_N>` placeholders and run the cells under the **Step 10:

The answers for code blocks in this section are as follows:

**CODE_BLOCK_27**
**CODE_BLOCK_29**

<details>
<summary>Answer</summary>
Expand All @@ -17,7 +17,7 @@ history_collection.create_index("session_id")
</div>
</details>

**CODE_BLOCK_28**
**CODE_BLOCK_30**

<details>
<summary>Answer</summary>
Expand All @@ -33,7 +33,7 @@ history_collection.create_index("session_id")
</div>
</details>

**CODE_BLOCK_29**
**CODE_BLOCK_31**

<details>
<summary>Answer</summary>
Expand All @@ -44,7 +44,7 @@ history_collection.insert_one(message)
</div>
</details>

**CODE_BLOCK_30**
**CODE_BLOCK_32**

<details>
<summary>Answer</summary>
Expand All @@ -55,7 +55,7 @@ history_collection.find({"session_id": session_id}).sort("timestamp", 1)
</div>
</details>

**CODE_BLOCK_31**
**CODE_BLOCK_33**

<details>
<summary>Answer</summary>
Expand All @@ -66,7 +66,7 @@ history_collection.find({"session_id": session_id}).sort("timestamp", 1)
</div>
</details>

**CODE_BLOCK_32**
**CODE_BLOCK_34**

<details>
<summary>Answer</summary>
Expand All @@ -78,7 +78,7 @@ messages.extend(message_history)
</div>
</details>

**CODE_BLOCK_33**
**CODE_BLOCK_35**

<details>
<summary>Answer</summary>
Expand All @@ -90,7 +90,7 @@ messages.append(user_message)
</div>
</details>

**CODE_BLOCK_34**
**CODE_BLOCK_36**

<details>
<summary>Answer</summary>
Expand Down

0 comments on commit f9bbd5a

Please sign in to comment.