From f9bbd5aad160770ca9fe5c81189af72bef090c85 Mon Sep 17 00:00:00 2001 From: ajosh0504 Date: Wed, 17 Jul 2024 08:41:45 -0700 Subject: [PATCH] Adding a reranking section --- docs/70-build-rag-app/3-add-reranking.mdx | 31 +++++++++++++++++++ ...m-responses.mdx => 4-stream-responses.mdx} | 4 +-- docs/80-add-memory/2-add-memory.mdx | 16 +++++----- 3 files changed, 41 insertions(+), 10 deletions(-) create mode 100644 docs/70-build-rag-app/3-add-reranking.mdx rename docs/70-build-rag-app/{3-stream-responses.mdx => 4-stream-responses.mdx} (96%) diff --git a/docs/70-build-rag-app/3-add-reranking.mdx b/docs/70-build-rag-app/3-add-reranking.mdx new file mode 100644 index 0000000..3ca4e0f --- /dev/null +++ b/docs/70-build-rag-app/3-add-reranking.mdx @@ -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 `` 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** + +
+Answer +
+```python +rerank_model.rank( + user_query, documents, return_documents=True, top_k=5 +) +``` +
+
+ +**CODE_BLOCK_26** + +
+Answer +
+```python +"\n\n".join([d.get("text", "") for d in reranked_documents]) +``` +
+
\ No newline at end of file diff --git a/docs/70-build-rag-app/3-stream-responses.mdx b/docs/70-build-rag-app/4-stream-responses.mdx similarity index 96% rename from docs/70-build-rag-app/3-stream-responses.mdx rename to docs/70-build-rag-app/4-stream-responses.mdx index 37529e8..4cb392e 100644 --- a/docs/70-build-rag-app/3-stream-responses.mdx +++ b/docs/70-build-rag-app/4-stream-responses.mdx @@ -6,7 +6,7 @@ Fill in any `` placeholders and run the cells under the **🦹‍ The answers for code blocks in this section are as follows: -**CODE_BLOCK_25** +**CODE_BLOCK_27**
Answer @@ -27,7 +27,7 @@ fw_client.chat.completions.create(
-**CODE_BLOCK_26** +**CODE_BLOCK_28**
Answer diff --git a/docs/80-add-memory/2-add-memory.mdx b/docs/80-add-memory/2-add-memory.mdx index ba07c89..fbb014d 100644 --- a/docs/80-add-memory/2-add-memory.mdx +++ b/docs/80-add-memory/2-add-memory.mdx @@ -6,7 +6,7 @@ Fill in any `` 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**
Answer @@ -17,7 +17,7 @@ history_collection.create_index("session_id")
-**CODE_BLOCK_28** +**CODE_BLOCK_30**
Answer @@ -33,7 +33,7 @@ history_collection.create_index("session_id")
-**CODE_BLOCK_29** +**CODE_BLOCK_31**
Answer @@ -44,7 +44,7 @@ history_collection.insert_one(message)
-**CODE_BLOCK_30** +**CODE_BLOCK_32**
Answer @@ -55,7 +55,7 @@ history_collection.find({"session_id": session_id}).sort("timestamp", 1)
-**CODE_BLOCK_31** +**CODE_BLOCK_33**
Answer @@ -66,7 +66,7 @@ history_collection.find({"session_id": session_id}).sort("timestamp", 1)
-**CODE_BLOCK_32** +**CODE_BLOCK_34**
Answer @@ -78,7 +78,7 @@ messages.extend(message_history)
-**CODE_BLOCK_33** +**CODE_BLOCK_35**
Answer @@ -90,7 +90,7 @@ messages.append(user_message)
-**CODE_BLOCK_34** +**CODE_BLOCK_36**
Answer