Update README.md
Browse files
README.md
CHANGED
@@ -26,17 +26,17 @@ How to use
|
|
26 |
Download data
|
27 |
Load to use with LangChain
|
28 |
|
29 |
-
|
30 |
pip install -qqq langchain sentence_transformers faiss-cpu huggingface_hub
|
31 |
import os
|
32 |
from langchain.embeddings import HuggingFaceEmbeddings, HuggingFaceInstructEmbeddings
|
33 |
|
34 |
from langchain.vectorstores.faiss import FAISS
|
35 |
from huggingface_hub import snapshot_download
|
36 |
-
|
37 |
|
38 |
# download the vectorstore for the book you want
|
39 |
-
|
40 |
cache_dir="cfa_level_1_cache"
|
41 |
vectorstore = snapshot_download(repo_id="nickmuchi/CFA_Level_1_Text_Embeddings",
|
42 |
repo_type="dataset",
|
@@ -44,21 +44,26 @@ vectorstore = snapshot_download(repo_id="nickmuchi/CFA_Level_1_Text_Embeddings",
|
|
44 |
allow_patterns=f"books/{book}/*", # to download only the one book
|
45 |
cache_dir=cache_dir,
|
46 |
)
|
47 |
-
|
48 |
# get path to the `vectorstore` folder that you just downloaded
|
49 |
# we'll look inside the `cache_dir` for the folder we want
|
|
|
50 |
target_dir = f"cfa/cfa_level_1"
|
|
|
51 |
|
52 |
# Walk through the directory tree recursively
|
|
|
53 |
for root, dirs, files in os.walk(cache_dir):
|
54 |
# Check if the target directory is in the list of directories
|
55 |
if target_dir in dirs:
|
56 |
# Get the full path of the target directory
|
57 |
target_path = os.path.join(root, target_dir)
|
|
|
58 |
|
59 |
# load embeddings
|
60 |
# this is what was used to create embeddings for the text
|
61 |
|
|
|
62 |
embed_instruction = "Represent the financial paragraph for document retrieval: "
|
63 |
query_instruction = "Represent the question for retrieving supporting documents: "
|
64 |
|
@@ -80,4 +85,6 @@ search = docsearch.similarity_search(question, k=4)
|
|
80 |
for item in search:
|
81 |
print(item.page_content)
|
82 |
print(f"From page: {item.metadata['page']}")
|
83 |
-
print("---")
|
|
|
|
|
|
26 |
Download data
|
27 |
Load to use with LangChain
|
28 |
|
29 |
+
```
|
30 |
pip install -qqq langchain sentence_transformers faiss-cpu huggingface_hub
|
31 |
import os
|
32 |
from langchain.embeddings import HuggingFaceEmbeddings, HuggingFaceInstructEmbeddings
|
33 |
|
34 |
from langchain.vectorstores.faiss import FAISS
|
35 |
from huggingface_hub import snapshot_download
|
36 |
+
```
|
37 |
|
38 |
# download the vectorstore for the book you want
|
39 |
+
```
|
40 |
cache_dir="cfa_level_1_cache"
|
41 |
vectorstore = snapshot_download(repo_id="nickmuchi/CFA_Level_1_Text_Embeddings",
|
42 |
repo_type="dataset",
|
|
|
44 |
allow_patterns=f"books/{book}/*", # to download only the one book
|
45 |
cache_dir=cache_dir,
|
46 |
)
|
47 |
+
```
|
48 |
# get path to the `vectorstore` folder that you just downloaded
|
49 |
# we'll look inside the `cache_dir` for the folder we want
|
50 |
+
```
|
51 |
target_dir = f"cfa/cfa_level_1"
|
52 |
+
```
|
53 |
|
54 |
# Walk through the directory tree recursively
|
55 |
+
```
|
56 |
for root, dirs, files in os.walk(cache_dir):
|
57 |
# Check if the target directory is in the list of directories
|
58 |
if target_dir in dirs:
|
59 |
# Get the full path of the target directory
|
60 |
target_path = os.path.join(root, target_dir)
|
61 |
+
```
|
62 |
|
63 |
# load embeddings
|
64 |
# this is what was used to create embeddings for the text
|
65 |
|
66 |
+
```
|
67 |
embed_instruction = "Represent the financial paragraph for document retrieval: "
|
68 |
query_instruction = "Represent the question for retrieving supporting documents: "
|
69 |
|
|
|
85 |
for item in search:
|
86 |
print(item.page_content)
|
87 |
print(f"From page: {item.metadata['page']}")
|
88 |
+
print("---")
|
89 |
+
|
90 |
+
```
|