-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4071052
commit ec183d3
Showing
6 changed files
with
84 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,4 @@ | |
/chunked_data.json | ||
/chunked_embeddings.json | ||
/embeddings.json | ||
/chroma-data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
hp: | ||
chunk-size: 300 | ||
overlap: 100 | ||
embeddings-model: "all-MiniLM-L6-v2" | ||
files: | ||
metadata: "data/eidc_metadata.json" | ||
extracted: "data/extracted_metadata.json" | ||
chunked: "data/chunked_data.json" | ||
embeddings: "data/embeddings.json" | ||
doc-store: "data/chroma-data" | ||
sample-size: 10 # sample size of 0 will process all data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,58 @@ | ||
from argparse import ArgumentParser | ||
import json | ||
import uuid | ||
|
||
import chromadb | ||
from chromadb.utils import embedding_functions | ||
|
||
|
||
def main(input_file: str, output_path: str, collection_name: str, embedding_model: str): | ||
print(collection_name) | ||
with open(input_file) as f: | ||
json_data = json.load(f) | ||
|
||
docs = [chunk["chunk"] for chunk in json_data] | ||
metas = [ | ||
{field: chunk[field] for field in ["field", "id", "index"]} | ||
for chunk in json_data | ||
] | ||
embs = [chunk["embedding"] for chunk in json_data] | ||
ids = [uuid.uuid4().hex for _ in json_data] | ||
|
||
func = embedding_functions.SentenceTransformerEmbeddingFunction( | ||
model_name=embedding_model | ||
) | ||
|
||
client = chromadb.PersistentClient(output_path) | ||
collection = client.create_collection( | ||
name=collection_name, embedding_function=func | ||
) | ||
collection.add(documents=docs, metadatas=metas, embeddings=embs, ids=ids) | ||
|
||
|
||
if __name__ == "__main__": | ||
parser = ArgumentParser("prepare_data.py") | ||
parser.add_argument("input_file", nargs="+", help="File containing chunks and embeddings to upload to document store") | ||
parser.add_argument("-o", "--output", help="The file to write the output to.") | ||
parser.add_argument( | ||
"input_file", | ||
help="File containing chunks and embeddings to upload to document store", | ||
) | ||
parser.add_argument( | ||
"-o", | ||
"--output", | ||
help="The file to write the output to.", | ||
default="data/chroma-data", | ||
) | ||
parser.add_argument( | ||
"-c", | ||
"--collection", | ||
help="Collection name to use in doc store.", | ||
default="eidc-data", | ||
) | ||
parser.add_argument( | ||
"-em", | ||
"--embedding_model", | ||
help="Embedding model to use in the doc store (must be the same as the function used to create embeddings.)", | ||
default="all-MiniLM-L6-v2", | ||
) | ||
args = parser.parse_args() | ||
main(args.input_file, args.output, args.collection, args.embedding_model) |
ec183d3
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
answer_relevancy: 0.4698974858684828
context_precision: 0.4974214494117698
answer_correctness: 0.5285432309309501
context_recall: 0.5459190810274471