Skip to content

Fixed Typos and Clarifying Concepts on Semantic Cache Notebook #75

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions notebooks/en/semantic_cache_chroma_vector_database.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -940,14 +940,14 @@
"cell_type": "code",
"source": [
"class semantic_cache:\n",
" def __init__(self, json_file=\"cache_file.json\", thresold=0.35):\n",
" def __init__(self, json_file=\"cache_file.json\", threshold=0.35):\n",
" # Initialize Faiss index with Euclidean distance\n",
" self.index, self.encoder = init_cache()\n",
"\n",
" # Set Euclidean distance threshold\n",
" # a distance of 0 means identicals sentences\n",
" # We only return from cache sentences under this thresold\n",
" self.euclidean_threshold = thresold\n",
" # We only return from cache sentences under this threshold\n",
" self.euclidean_threshold = threshold\n",
"\n",
" self.json_file = json_file\n",
" self.cache = retrieve_cache(self.json_file)\n",
Expand All @@ -960,10 +960,17 @@
" embedding = self.encoder.encode([question])\n",
"\n",
" # Search for the nearest neighbor in the index\n",
" self.index.nprobe = 8\n",
" self.index.nprobe = 8 # Number of nearby cells to search\n",
"\n",
" # D - Array of Distances between the query vector and nearest neighbors\n",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

repetitive comments here breaks readability of the code sometimes, would be nice to instead have a docstring

" # I - Array of Indices of the nearest neighbors found in the index\n",
" # Both are Shape (n, k) where n = number of questions in the embedding array and k = number of returned vectors\n",
" D, I = self.index.search(embedding, 1)\n",
"\n",
" # In this case, we only are expecting one vector in both the distance and index array (k=1)\n",
" # Check if the distance array is valid\n",
" if D[0] >= 0:\n",
" # Check if the index is valid and check if the distance is below the threshold value\n",
" if I[0][0] >= 0 and D[0][0] <= self.euclidean_threshold:\n",
" row_id = int(I[0][0])\n",
"\n",
Expand Down