From 61dab1f31ea9c6b4aa90e9cd57c0c1f6739b0f8d Mon Sep 17 00:00:00 2001 From: Max Shkutnyk Date: Fri, 17 Jan 2025 09:00:40 +0200 Subject: [PATCH] Reformat code examples for semantic search intro section --- .../deeper-semantic-search.mdx | 83 ++++++++++--------- .../fine-tuning-for-rerank.mdx | 67 ++++++++++----- .../generating-answers.mdx | 11 ++- .../intro-semantic-search/keyword-search.mdx | 25 ++++-- .../multilingual-movie-search.mdx | 2 +- .../intro-semantic-search/reranking-2.mdx | 10 +-- 6 files changed, 119 insertions(+), 79 deletions(-) diff --git a/fern/pages/llm-university/intro-semantic-search/deeper-semantic-search.mdx b/fern/pages/llm-university/intro-semantic-search/deeper-semantic-search.mdx index 935cf4ab1..49770e94d 100644 --- a/fern/pages/llm-university/intro-semantic-search/deeper-semantic-search.mdx +++ b/fern/pages/llm-university/intro-semantic-search/deeper-semantic-search.mdx @@ -30,7 +30,7 @@ As you've seen before, semantic search goes way beyond keyword search. The appli ### 1. Download the Dependencies ```python PYTHON -#title Import libraries (Run this cell to execute required code) {display-mode: "form"} +# title Import libraries (Run this cell to execute required code) {display-mode: "form"} import cohere import numpy as np @@ -43,8 +43,9 @@ import altair as alt from sklearn.metrics.pairwise import cosine_similarity from annoy import AnnoyIndex import warnings -warnings.filterwarnings('ignore') -pd.set_option('display.max_colwidth', None) + +warnings.filterwarnings("ignore") +pd.set_option("display.max_colwidth", None) ``` ### 2. Get the Archive of Questions @@ -83,14 +84,15 @@ To get a thousand embeddings of this length should take a few seconds. ```python PYTHON # Paste your API key here. Remember to not share publicly -api_key = '' +api_key = "" # Create and retrieve a Cohere API key from dashboard.cohere.ai/welcome/register co = cohere.Client(api_key) # Get the embeddings -embeds = co.embed(texts=list(df['text']), - model='embed-english-v2.0').embeddings +embeds = co.embed( + texts=list(df["text"]), model="embed-english-v2.0" +).embeddings ``` ### 4. Build the Index, search Using an Index and Conduct Nearest Neighbour Search @@ -101,12 +103,12 @@ Let's build an index using the library called