From 8ca9e65aaec1d94331af89c7a9b79c83ea66e72a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucas=20H=C3=A4nke=20de=20Cansino?= Date: Fri, 1 Dec 2023 06:22:05 +0100 Subject: [PATCH 01/10] Create jinapeft.md --- docs/embeddings/jinapeft.md | 71 +++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 docs/embeddings/jinapeft.md diff --git a/docs/embeddings/jinapeft.md b/docs/embeddings/jinapeft.md new file mode 100644 index 0000000..d839417 --- /dev/null +++ b/docs/embeddings/jinapeft.md @@ -0,0 +1,71 @@ +--- +--- + +# Jina AI with PEFT and GPU acceleration + +import Tabs from '@theme/Tabs'; +import TabItem from '@theme/TabItem'; + +
Select a language
+ + + + + + +This component provides a convenient wrapper around JinaAI's alpine base embeddings model or as well as the optional of additional PEFT config. This embedding function runs completely local, and does not require an API key. Ask @Luke on discord if you need help with PEFT on your data. + + + + +This embedding function relies on the `peft`, `torch` & `transformers` python package, which you can install with `pip install transformers torch peft`. +for CPU inference +```python +chroma_embedding_fnc = embedding_functions.JinaAIEmbeddingsFunction(device = "cpu") +``` +for GPU inference +```python +chroma_embedding_fnc = embedding_functions.JinaAIEmbeddingsFunction(device = "cuda") +chroma_collection = chroma_client.get_or_create_collection( + name="test_collection", + embedding_function=chroma_embedding_fnc, + metadata={ + "hnsw:space": "cosine", # "l2", "ip, "or "cosine". The default is "l2". + "hnsw:construction_ef": 10240, # Number of docs # https://github.com/nmslib/hnswlib + "hnsw:M": 640, # Docs retrieved + }, +) +chroma_collection.add( + documents=[ + "Lisa Su: DoB 06/07/1987 -- President and Chief Executive Officer Yeah. Sure, Joe. So, we've been engaging broadly with the customer set. I think in the last earnings call, we said that our engagements had increased seven times.", + "Jensen Huang: SSN 456-345-234-345 -- President and Chief Executive Officer The world has something along the lines of about $1 trillion worth of data centers installed in the cloud and enterprise and otherwise.", + "Jensen Huang: DoB 12/05/67 -- President and Chief Executive Officer The world has something along the lines of about $1 trillion worth of data centers installed in the cloud and enterprise and otherwise.", + "Elon Musk: Date of birth 12th of July '56 is the CEO of Tesla and SpaceX and one of the co-founders of PayPal.", + ], + metadatas=[ + {"chapter": "3", "verse": "16"}, + {"chapter": "3", "verse": "5"}, + {"chapter": "29", "verse": "11"}, + {"chapter": "29", "verse": "11"}, + ], + ids=["id1", "id2", "id3", "id4"], +) +query_result = chroma_collection.query( + query_texts=[ + "Lisa Su'S Date of Birth", + "Elon Musk's Date of Birth", + "Jensen Huang's Date of Birth", + ], + n_results=10, + include=["distances"] + # where={"metadata_field": "is_equal_to_this"}, + # where_document={"$contains":"search_string"} +) +print(query_result) +``` +You can pass in an optional `model_name` argument, which lets you choose which Jina model to use. By default, Chroma uses `jina-embedding-v2-base-en`. + + + + + From dff576f6e9387ba93d80336119c4850ee7f2a95b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucas=20H=C3=A4nke=20de=20Cansino?= Date: Fri, 1 Dec 2023 06:22:20 +0100 Subject: [PATCH 02/10] Rename jinapeft.md to jinaaipeft.md --- docs/embeddings/{jinapeft.md => jinaaipeft.md} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename docs/embeddings/{jinapeft.md => jinaaipeft.md} (100%) diff --git a/docs/embeddings/jinapeft.md b/docs/embeddings/jinaaipeft.md similarity index 100% rename from docs/embeddings/jinapeft.md rename to docs/embeddings/jinaaipeft.md From 9d31bb93e8df158bdd6e945780a41046b0ee795e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucas=20H=C3=A4nke=20de=20Cansino?= Date: Fri, 1 Dec 2023 06:25:30 +0100 Subject: [PATCH 03/10] Update jinaaipeft.md --- docs/embeddings/jinaaipeft.md | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/docs/embeddings/jinaaipeft.md b/docs/embeddings/jinaaipeft.md index d839417..a5a3525 100644 --- a/docs/embeddings/jinaaipeft.md +++ b/docs/embeddings/jinaaipeft.md @@ -13,7 +13,7 @@ import TabItem from '@theme/TabItem'; -This component provides a convenient wrapper around JinaAI's alpine base embeddings model or as well as the optional of additional PEFT config. This embedding function runs completely local, and does not require an API key. Ask @Luke on discord if you need help with PEFT on your data. +This component provides a convenient wrapper around JinaAI's alpine base embeddings model or with optional PEFT config. This embedding function runs completely local, and does not require an API key. @@ -23,16 +23,18 @@ for CPU inference ```python chroma_embedding_fnc = embedding_functions.JinaAIEmbeddingsFunction(device = "cpu") ``` -for GPU inference +for GPU inference with PEFT ```python -chroma_embedding_fnc = embedding_functions.JinaAIEmbeddingsFunction(device = "cuda") +path_to_lora_config_directory = your_lora_path +chroma_embedding_fnc = embedding_functions.JinaAIEmbeddingsFunction(device = "cuda", adapters_path = path_to_lora_config_directory) chroma_collection = chroma_client.get_or_create_collection( name="test_collection", embedding_function=chroma_embedding_fnc, metadata={ + # https://github.com/nmslib/hnswlib "hnsw:space": "cosine", # "l2", "ip, "or "cosine". The default is "l2". - "hnsw:construction_ef": 10240, # Number of docs # https://github.com/nmslib/hnswlib - "hnsw:M": 640, # Docs retrieved + "hnsw:construction_ef": 1024, + "hnsw:M": 64, }, ) chroma_collection.add( From 52ab0d46c28e712fb4bc6f7406c8e53d43e86f40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucas=20H=C3=A4nke=20de=20Cansino?= Date: Fri, 1 Dec 2023 06:26:10 +0100 Subject: [PATCH 04/10] Update jinaaipeft.md --- docs/embeddings/jinaaipeft.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/embeddings/jinaaipeft.md b/docs/embeddings/jinaaipeft.md index a5a3525..8e2b4e5 100644 --- a/docs/embeddings/jinaaipeft.md +++ b/docs/embeddings/jinaaipeft.md @@ -19,11 +19,11 @@ This component provides a convenient wrapper around JinaAI's alpine base embeddi This embedding function relies on the `peft`, `torch` & `transformers` python package, which you can install with `pip install transformers torch peft`. -for CPU inference +## CPU inference ```python chroma_embedding_fnc = embedding_functions.JinaAIEmbeddingsFunction(device = "cpu") ``` -for GPU inference with PEFT +## GPU inference with PEFT ```python path_to_lora_config_directory = your_lora_path chroma_embedding_fnc = embedding_functions.JinaAIEmbeddingsFunction(device = "cuda", adapters_path = path_to_lora_config_directory) From 0aad911b623e37e3f1d7adde3f707d7b898aab74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucas=20H=C3=A4nke=20de=20Cansino?= Date: Fri, 1 Dec 2023 06:26:23 +0100 Subject: [PATCH 05/10] Update jinaaipeft.md --- docs/embeddings/jinaaipeft.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/embeddings/jinaaipeft.md b/docs/embeddings/jinaaipeft.md index 8e2b4e5..681498c 100644 --- a/docs/embeddings/jinaaipeft.md +++ b/docs/embeddings/jinaaipeft.md @@ -19,7 +19,7 @@ This component provides a convenient wrapper around JinaAI's alpine base embeddi This embedding function relies on the `peft`, `torch` & `transformers` python package, which you can install with `pip install transformers torch peft`. -## CPU inference +## CPU inference with Base Model ```python chroma_embedding_fnc = embedding_functions.JinaAIEmbeddingsFunction(device = "cpu") ``` From c65feb0b170de66ca2222b65db9daaa379b55fda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucas=20H=C3=A4nke=20de=20Cansino?= Date: Fri, 1 Dec 2023 06:26:33 +0100 Subject: [PATCH 06/10] Update jinaaipeft.md --- docs/embeddings/jinaaipeft.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/embeddings/jinaaipeft.md b/docs/embeddings/jinaaipeft.md index 681498c..caaafda 100644 --- a/docs/embeddings/jinaaipeft.md +++ b/docs/embeddings/jinaaipeft.md @@ -19,7 +19,7 @@ This component provides a convenient wrapper around JinaAI's alpine base embeddi This embedding function relies on the `peft`, `torch` & `transformers` python package, which you can install with `pip install transformers torch peft`. -## CPU inference with Base Model +## CPU inference with Alpine Base Model ```python chroma_embedding_fnc = embedding_functions.JinaAIEmbeddingsFunction(device = "cpu") ``` From 71f6a4c2799c165d11d566ccf3f9bdf5aa04161b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucas=20H=C3=A4nke=20de=20Cansino?= Date: Fri, 1 Dec 2023 06:26:55 +0100 Subject: [PATCH 07/10] Update jinaaipeft.md --- docs/embeddings/jinaaipeft.md | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/docs/embeddings/jinaaipeft.md b/docs/embeddings/jinaaipeft.md index caaafda..c194f8b 100644 --- a/docs/embeddings/jinaaipeft.md +++ b/docs/embeddings/jinaaipeft.md @@ -3,16 +3,6 @@ # Jina AI with PEFT and GPU acceleration -import Tabs from '@theme/Tabs'; -import TabItem from '@theme/TabItem'; - -
Select a language
- - - - - - This component provides a convenient wrapper around JinaAI's alpine base embeddings model or with optional PEFT config. This embedding function runs completely local, and does not require an API key. From 60ea43a314ea2f70b5ba6ce0f9916ada751b36cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucas=20H=C3=A4nke=20de=20Cansino?= Date: Fri, 1 Dec 2023 06:29:23 +0100 Subject: [PATCH 08/10] Update jinaaipeft.md --- docs/embeddings/jinaaipeft.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/embeddings/jinaaipeft.md b/docs/embeddings/jinaaipeft.md index c194f8b..c173025 100644 --- a/docs/embeddings/jinaaipeft.md +++ b/docs/embeddings/jinaaipeft.md @@ -1,7 +1,7 @@ --- --- -# Jina AI with PEFT and GPU acceleration +# Local Jina AI with PEFT and GPU acceleration This component provides a convenient wrapper around JinaAI's alpine base embeddings model or with optional PEFT config. This embedding function runs completely local, and does not require an API key. From f02f01ad721938970cf51cf2c8cc0a86ca4ebead Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucas=20H=C3=A4nke=20de=20Cansino?= Date: Fri, 1 Dec 2023 06:29:40 +0100 Subject: [PATCH 09/10] Update jinaaipeft.md --- docs/embeddings/jinaaipeft.md | 5 ----- 1 file changed, 5 deletions(-) diff --git a/docs/embeddings/jinaaipeft.md b/docs/embeddings/jinaaipeft.md index c173025..80ed8a1 100644 --- a/docs/embeddings/jinaaipeft.md +++ b/docs/embeddings/jinaaipeft.md @@ -56,8 +56,3 @@ query_result = chroma_collection.query( print(query_result) ``` You can pass in an optional `model_name` argument, which lets you choose which Jina model to use. By default, Chroma uses `jina-embedding-v2-base-en`. - -
- - -
From d8eff4854ac33937e3cbecd831efa6f0faf19a49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucas=20H=C3=A4nke=20de=20Cansino?= Date: Fri, 1 Dec 2023 06:38:45 +0100 Subject: [PATCH 10/10] Update jinaaipeft.md --- docs/embeddings/jinaaipeft.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/embeddings/jinaaipeft.md b/docs/embeddings/jinaaipeft.md index 80ed8a1..91eb826 100644 --- a/docs/embeddings/jinaaipeft.md +++ b/docs/embeddings/jinaaipeft.md @@ -5,6 +5,8 @@ This component provides a convenient wrapper around JinaAI's alpine base embeddings model or with optional PEFT config. This embedding function runs completely local, and does not require an API key. +Detailed Guide for LoRA PEFT for semantic search can be found [here](https://huggingface.co/docs/peft/task_guides/semantic-similarity-lora). +