AyoubChLin commited on
Commit
8dd99a4
1 Parent(s): 6b54693
Files changed (2) hide show
  1. SearchEngine.py +14 -4
  2. app.py +4 -5
SearchEngine.py CHANGED
@@ -3,14 +3,24 @@ from chromadb.config import Settings
3
  import chromadb
4
 
5
  class searchengine:
 
 
 
 
 
 
 
 
6
  def __init__(self, model_name,collection_name):
 
7
  self.sentence_transformer_ef = embedding_functions.SentenceTransformerEmbeddingFunction(
8
- model_name = model_name
9
- )
10
  self.chroma_client = chromadb.Client(
11
- )
12
  self.collection = self.chroma_client.get_or_create_collection(name=collection_name)
13
-
 
14
  def add(self, text , metadata,id):
15
  self.collection.add(
16
  documents = [text],
 
3
  import chromadb
4
 
5
  class searchengine:
6
+ instance = None
7
+
8
+ def __new__(cls, model_name, collection_name):
9
+ if cls.instance is None:
10
+ cls.instance = super(searchengine, cls).__new__(cls)
11
+ return cls.instance
12
+ else:
13
+ return cls.instance
14
  def __init__(self, model_name,collection_name):
15
+
16
  self.sentence_transformer_ef = embedding_functions.SentenceTransformerEmbeddingFunction(
17
+ model_name = model_name
18
+ )
19
  self.chroma_client = chromadb.Client(
20
+ )
21
  self.collection = self.chroma_client.get_or_create_collection(name=collection_name)
22
+ self.initialized = True
23
+
24
  def add(self, text , metadata,id):
25
  self.collection.add(
26
  documents = [text],
app.py CHANGED
@@ -6,15 +6,14 @@ import logging
6
  # Set up logging
7
  logging.basicConfig(level=logging.INFO)
8
  logger = logging.getLogger(__name__)
 
 
9
 
 
10
 
11
  def main():
12
  st.title("ChromaDB Search Engine")
13
- repoid = 'sentence-transformers/all-MiniLM-L6-v2'
14
- model_name = "all-MiniLM-L6-v2"
15
- collection_name = "docs"
16
-
17
- search_engine = searchengine(model_name, collection_name)
18
 
19
  st.sidebar.header("Add Document")
20
  text_input = st.sidebar.text_area("Text")
 
6
  # Set up logging
7
  logging.basicConfig(level=logging.INFO)
8
  logger = logging.getLogger(__name__)
9
+ model_name = "all-MiniLM-L6-v2"
10
+ collection_name = "docs"
11
 
12
+ search_engine = searchengine(model_name, collection_name)
13
 
14
  def main():
15
  st.title("ChromaDB Search Engine")
16
+
 
 
 
 
17
 
18
  st.sidebar.header("Add Document")
19
  text_input = st.sidebar.text_area("Text")