Skip to content

Commit

Permalink
Final QA (#457)
Browse files Browse the repository at this point in the history
  • Loading branch information
gahjelle authored Nov 7, 2023
1 parent 5102449 commit d9a1323
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 8 deletions.
2 changes: 1 addition & 1 deletion embeddings-and-vector-databases-with-chromadb/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Embeddings and Vector Databases With ChromaDB

Supporting code for the Real Python tutorial [Embeddings and Vector Databases With ChromaDB](https://realpython.com/embeddings-and-vector-databases-with-chromadb/).
Supporting code for the Real Python tutorial [Embeddings and Vector Databases With ChromaDB](https://realpython.com/chromadb-vector-database/).

To run the code in this tutorial, you should have `numpy`, `spacy`, `sentence-transformers`, `chromadb`, `polars`, `more-itertools`, and `openai` installed in your environment.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,4 @@ def prepare_car_reviews_data(
documents = car_review_db_data["Review"].to_list()
metadatas = car_review_db_data.drop("Review").to_dicts()

chroma_data = {"ids": ids, "documents": documents, "metadatas": metadatas}

return chroma_data
return {"ids": ids, "documents": documents, "metadatas": metadatas}
4 changes: 2 additions & 2 deletions embeddings-and-vector-databases-with-chromadb/chroma_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
def build_chroma_collection(
chroma_path: pathlib.Path,
collection_name: str,
embbeding_func_name: str,
embedding_func_name: str,
ids: list[str],
documents: list[str],
metadatas: list[dict],
Expand All @@ -19,7 +19,7 @@ def build_chroma_collection(
chroma_client = chromadb.PersistentClient(chroma_path)

embedding_func = embedding_functions.SentenceTransformerEmbeddingFunction(
model_name=embbeding_func_name
model_name=embedding_func_name
)

collection = chroma_client.create_collection(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
def compute_cosine_similarity(u: np.ndarray, v: np.ndarray) -> float:
"""Compute the cosine similarity between two vectors"""

return u.dot(v) / (np.linalg.norm(u) * np.linalg.norm(v))
return (u @ v) / (np.linalg.norm(u) * np.linalg.norm(v))
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@

# Dot product
print(np.sum(v1 * v2))
print(v1.dot(v3))
print(v1 @ v3)

0 comments on commit d9a1323

Please sign in to comment.