calmgoose commited on
Commit
d11e973
1 Parent(s): 396328f

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +74 -0
README.md CHANGED
@@ -1,3 +1,77 @@
1
  ---
2
  license: apache-2.0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
  license: apache-2.0
3
+ task_categories:
4
+ - question-answering
5
+ - summarization
6
+ - conversational
7
+ - sentence-similarity
8
+ language:
9
+ - en
10
+ pretty_name: Embeddings for George Orwell's 1984
11
+ tags:
12
+ - faiss
13
+ - langchain
14
+ - instructor embeddings
15
+ - vector stores
16
+ - books
17
+ - LLM
18
  ---
19
+ # Vector store of embeddings for the book "1984" by George Orwell
20
+
21
+ This is a [faiss](https://github.com/facebookresearch/faiss) vector store created with [instructor embeddings](https://github.com/HKUNLP/instructor-embedding) using [LangChain](https://langchain.readthedocs.io/en/latest/modules/indexes/examples/embeddings.html#instructembeddings) . Use it for similarity search, question answering or anything else that leverages embeddings! 😃
22
+
23
+ Creating these embeddings can take a while so here's a convenient, downloadable one 🤗
24
+
25
+
26
+ ## How to use
27
+
28
+ 1. Download data
29
+ 2. Load to use with LangChain
30
+
31
+ pip install -qqq langchain InstructorEmbedding sentence_transformers faiss-cpu huggingface_hub
32
+
33
+ ```python
34
+ import os
35
+ from langchain.embeddings import HuggingFaceInstructEmbeddings
36
+ from langchain.vectorstores.faiss import FAISS
37
+ from huggingface_hub import snapshot_download
38
+
39
+ # download the `vectorstore` folder
40
+ cache_dir="orwell_faiss"
41
+ vectorstore = snapshot_download(repo_id="calmgoose/orwell-1984_faiss-instructembeddings",
42
+ repo_type="dataset",
43
+ revision="main",
44
+ allow_patterns="vectorstore/*",
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 = "vectorstore"
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 book
61
+ embeddings = HuggingFaceInstructEmbeddings(
62
+ embed_instruction="Represent the book passage for retrieval: ",
63
+ query_instruction="Represent the question for retrieving supporting texts from the book passage: "
64
+ )
65
+
66
+ # load vector store to use with langchain
67
+ docsearch = FAISS.load_local(folder_path=target_path, embeddings=embeddings)
68
+
69
+ # similarity search
70
+ question = "Who is big brother?"
71
+ search = docsearch.similarity_search(question, k=4)
72
+
73
+ for item in search:
74
+ print(item.page_content)
75
+ print(f"From page: {item.metadata['page']}")
76
+ print("---")
77
+ ```