oryx1729 commited on
Commit
8df121c
1 Parent(s): 91eb887

Add indexing

Browse files
app.py CHANGED
@@ -1,12 +1,9 @@
 
1
  import logging
2
  import sys
3
 
4
  import streamlit as st
5
- from haystack import Document
6
  from haystack import Pipeline
7
- from haystack.document_stores import InMemoryDocumentStore
8
- from haystack.nodes import EmbeddingRetriever
9
- from haystack.nodes import FARMReader
10
 
11
  logging.basicConfig(
12
  level=logging.DEBUG,
@@ -17,29 +14,26 @@ logging.basicConfig(
17
 
18
  p = None
19
 
 
20
  def app_init():
21
- docs = [Document(id='1', content='His name is John.'),
22
- Document(id='2', content='Her name is Jane.'),
23
- Document(id='3', content='My name is Haystack.')]
24
- ds = InMemoryDocumentStore()
25
- ds.write_documents(docs)
26
- retriever = EmbeddingRetriever(
27
- document_store=ds,
28
- embedding_model="sentence-transformers/multi-qa-mpnet-base-dot-v1",
29
- model_format="sentence_transformers",
30
- )
31
- ds.update_embeddings(retriever)
32
- reader = FARMReader("deepset/minilm-uncased-squad2", use_gpu=False)
33
- p = Pipeline()
34
- p.add_node(component=retriever, name='retriever', inputs=['Query'])
35
- p.add_node(component=reader, name='reader', inputs=['retriever'])
36
 
37
 
38
  def main():
39
  app_init()
40
  st.title("Haystack Demo")
41
  input = st.text_input("Query ...")
42
- st.text(p.run(input))
 
43
 
44
  if __name__ == "__main__":
45
- main()
 
1
+ import glob
2
  import logging
3
  import sys
4
 
5
  import streamlit as st
 
6
  from haystack import Pipeline
 
 
 
7
 
8
  logging.basicConfig(
9
  level=logging.DEBUG,
 
14
 
15
  p = None
16
 
17
+
18
  def app_init():
19
+ indexing_pipeline = Pipeline.load_from_yaml("pipeline.yaml", pipeline_name="indexing")
20
+ file_paths = glob.glob("data/*")
21
+ ds = indexing_pipeline.get_node("DocumentStore")
22
+ ds.delete_all_documents()
23
+ indexing_pipeline.run(file_paths=file_paths)
24
+ ds.update_embeddings(indexing_pipeline.get_node("Retriever"))
25
+ ds.save(config_path="my_faiss_config.json", index_path="my_faiss_index.faiss")
26
+
27
+ global p
28
+ p = Pipeline.load_from_yaml("pipeline.yaml", pipeline_name="query")
 
 
 
 
 
29
 
30
 
31
  def main():
32
  app_init()
33
  st.title("Haystack Demo")
34
  input = st.text_input("Query ...")
35
+ st.text(p.run(str(input or "test")))
36
+
37
 
38
  if __name__ == "__main__":
39
+ main()
faiss_document_store.db ADDED
Binary file (73.7 kB). View file
 
my_faiss_config.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"faiss_config_path": "my_faiss_config.json", "embedding_dim": 768}
my_faiss_index.faiss ADDED
Binary file (6.19 kB). View file
 
requirements.txt CHANGED
@@ -1 +1 @@
1
- farm-haystack
 
1
+ farm-haystack[faiss]