Mattral commited on
Commit
0cfd0bb
·
verified ·
1 Parent(s): c84b3b4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +2 -8
app.py CHANGED
@@ -65,21 +65,15 @@ def get_url_content(url):
65
  return None
66
 
67
 
68
-
69
  @st.cache_resource
70
  def get_retriever(urls):
71
- documents = DocumentArray([get_url_content(url) for url in urls])
72
 
73
- # Load the model and encode document texts directly
74
  model = SentenceTransformer('all-MiniLM-L6-v2')
75
- documents.embeddings = model.encode(documents.texts, show_progress_bar=True)
76
-
77
- # Applying HNSW for efficient similarity search
78
- documents.embeddings.faiss.ann['HNSW'] = {'nlinks': 16}
79
 
80
  return documents
81
 
82
-
83
  @st.cache_resource
84
  def create_chain(_retriever):
85
  # A stream handler to direct streaming output on the chat screen.
 
65
  return None
66
 
67
 
 
68
  @st.cache_resource
69
  def get_retriever(urls):
70
+ documents = DocumentArray([doc for url in urls if (doc := get_url_content(url)) is not None])
71
 
 
72
  model = SentenceTransformer('all-MiniLM-L6-v2')
73
+ documents.embeddings = model.encode([doc.text for doc in documents], show_progress_bar=True)
 
 
 
74
 
75
  return documents
76
 
 
77
  @st.cache_resource
78
  def create_chain(_retriever):
79
  # A stream handler to direct streaming output on the chat screen.