Rustamshry commited on
Commit
43795fe
·
verified ·
1 Parent(s): 2123dcb

Update src/chroma_utils.py

Browse files
Files changed (1) hide show
  1. src/chroma_utils.py +60 -60
src/chroma_utils.py CHANGED
@@ -1,61 +1,61 @@
1
- import chromadb
2
- from chromadb.utils import embedding_functions
3
- import os
4
- import uuid
5
-
6
- PERSIST_DIRECTORY = "./chroma_db_data"
7
-
8
- os.makedirs(PERSIST_DIRECTORY, exist_ok=True)
9
-
10
- client = chromadb.PersistentClient(path=PERSIST_DIRECTORY)
11
-
12
- embedding_fn = embedding_functions.SentenceTransformerEmbeddingFunction(model_name="sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2")
13
-
14
- resume_collection = client.get_or_create_collection(name="resume_collection", embedding_function=embedding_fn)
15
-
16
- job_collection = client.get_or_create_collection(name="job_collection", embedding_function=embedding_fn)
17
-
18
-
19
- def add_to_resume_chroma(embedding, metadata):
20
-
21
- unique_id = str(uuid.uuid4())
22
- resume_collection.add(ids=[unique_id], embeddings=[embedding], metadatas=[metadata])
23
- return unique_id
24
-
25
- def add_to_job_chroma(embedding, metadata):
26
-
27
- unique_id = str(uuid.uuid4())
28
- job_collection.add(ids=[unique_id], embeddings=[embedding], metadatas=[metadata])
29
- return unique_id
30
-
31
- def search_resume_chroma(query_embedding, k=10):
32
-
33
- results = resume_collection.query(
34
- query_embeddings=[query_embedding],
35
- n_results=k,
36
- include=["embeddings", "metadatas"]
37
- )
38
- return results
39
-
40
- def search_job_chroma(query_embedding, k=10):
41
-
42
- results = job_collection.query(
43
- query_embeddings=[query_embedding],
44
- n_results=k,
45
- include=["embeddings", "metadatas"]
46
- )
47
- return results
48
-
49
- def get_all_jobs_from_chroma():
50
-
51
- results = job_collection.get(include=["embeddings", "metadatas"])
52
- return results['ids'], results['embeddings'], results['metadatas']
53
-
54
- def delete_resume_from_chroma(unique_id):
55
- resume_collection.delete(ids=[unique_id])
56
-
57
- def delete_job_from_chroma(unique_id):
58
- job_collection.delete(ids=[unique_id])
59
-
60
-
61
 
 
1
+ import chromadb
2
+ from chromadb.utils import embedding_functions
3
+ import os
4
+ import uuid
5
+
6
+ PERSIST_DIRECTORY = "/tmp/chroma_db_data"
7
+
8
+ os.makedirs(PERSIST_DIRECTORY, exist_ok=True)
9
+
10
+ client = chromadb.PersistentClient(path=PERSIST_DIRECTORY)
11
+
12
+ embedding_fn = embedding_functions.SentenceTransformerEmbeddingFunction(model_name="sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2")
13
+
14
+ resume_collection = client.get_or_create_collection(name="resume_collection", embedding_function=embedding_fn)
15
+
16
+ job_collection = client.get_or_create_collection(name="job_collection", embedding_function=embedding_fn)
17
+
18
+
19
+ def add_to_resume_chroma(embedding, metadata):
20
+
21
+ unique_id = str(uuid.uuid4())
22
+ resume_collection.add(ids=[unique_id], embeddings=[embedding], metadatas=[metadata])
23
+ return unique_id
24
+
25
+ def add_to_job_chroma(embedding, metadata):
26
+
27
+ unique_id = str(uuid.uuid4())
28
+ job_collection.add(ids=[unique_id], embeddings=[embedding], metadatas=[metadata])
29
+ return unique_id
30
+
31
+ def search_resume_chroma(query_embedding, k=10):
32
+
33
+ results = resume_collection.query(
34
+ query_embeddings=[query_embedding],
35
+ n_results=k,
36
+ include=["embeddings", "metadatas"]
37
+ )
38
+ return results
39
+
40
+ def search_job_chroma(query_embedding, k=10):
41
+
42
+ results = job_collection.query(
43
+ query_embeddings=[query_embedding],
44
+ n_results=k,
45
+ include=["embeddings", "metadatas"]
46
+ )
47
+ return results
48
+
49
+ def get_all_jobs_from_chroma():
50
+
51
+ results = job_collection.get(include=["embeddings", "metadatas"])
52
+ return results['ids'], results['embeddings'], results['metadatas']
53
+
54
+ def delete_resume_from_chroma(unique_id):
55
+ resume_collection.delete(ids=[unique_id])
56
+
57
+ def delete_job_from_chroma(unique_id):
58
+ job_collection.delete(ids=[unique_id])
59
+
60
+
61