From 84f7ad1f66c344b21ea5dfc6e8528c9ef1f2a04b Mon Sep 17 00:00:00 2001 From: tlane25 Date: Tue, 6 Aug 2024 20:18:32 -0400 Subject: [PATCH] update: incorporated absolute imports, server runs as a module --- Pipfile.lock | 126 ++++++++--------- cleanup.py | 2 + evals.py | 8 +- pipeline/hybrid_search/vector.py | 225 +++++++++++++++++++++++-------- pipeline/mongo_util.py | 9 +- routers/__init__.py | 0 server.py | 20 ++- util/__init__.py | 0 8 files changed, 256 insertions(+), 134 deletions(-) create mode 100644 routers/__init__.py create mode 100644 util/__init__.py diff --git a/Pipfile.lock b/Pipfile.lock index 3d2c569..e0b9e7a 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -181,20 +181,20 @@ }, "boto3": { "hashes": [ - "sha256:7ca22adef4c77ee128e1e1dc7d48bc9512a87cc6fe3d771b3f913d5ecd41c057", - "sha256:864f06528c583dc7b02adf12db395ecfadbf9cb0da90e907e848ffb27128ce19" + "sha256:445239ea2ba7f4084ddbd71f721c14d0a6d08e06f6ba51b5403a16b6544b3f1e", + "sha256:e8d2e128c74e84199edccdc3a6b4b1c6fb36d6fdb5688eb92931827f02c6fa5b" ], "index": "pypi", "markers": "python_version >= '3.8'", - "version": "==1.34.154" + "version": "==1.34.155" }, "botocore": { "hashes": [ - "sha256:4eef4b1bb809b382ba9dc9c88f5fcc4a133f221a1acb693ee6bee4de9f325979", - "sha256:64d9b4c85a504d77cb56dabb2ad717cd8e1717424a88edb458b01d1e5797262a" + "sha256:3aa88abfef23909f68d3e6679a3d4b4bb3c6288a6cfbf9e253aa68dac8edad64", + "sha256:f2696c11bb0cad627d42512937befd2e3f966aedd15de00d90ee13cf7a16b328" ], "markers": "python_version >= '3.8'", - "version": "==1.34.154" + "version": "==1.34.155" }, "certifi": { "hashes": [ @@ -901,12 +901,12 @@ }, "llama-index-llms-openai": { "hashes": [ - "sha256:37c2d1159b56607d3a807d90260ee25b4f002086d6251c7272afbc53f2514603", - "sha256:8da0e90d4a558667d2b9cf1b3f577a4cb7723b7680ed6d22027b0baf9cd5999e" + "sha256:4b87836f08ef32b04436646431c3fb57eacf74536270e3291fbb652d04012c62", + "sha256:d07312dcf62ba7654310633dfd5c02d39bbe32761cbe8b121dd338d3b6a5b350" ], "index": "pypi", "markers": "python_full_version >= '3.8.1' and python_version < '4.0'", - "version": "==0.1.27" + "version": "==0.1.28" }, "llama-index-multi-modal-llms-openai": { "hashes": [ @@ -1840,60 +1840,62 @@ }, "pyyaml": { "hashes": [ - "sha256:04ac92ad1925b2cff1db0cfebffb6ffc43457495c9b3c39d3fcae417d7125dc5", - "sha256:062582fca9fabdd2c8b54a3ef1c978d786e0f6b3a1510e0ac93ef59e0ddae2bc", - "sha256:0d3304d8c0adc42be59c5f8a4d9e3d7379e6955ad754aa9d6ab7a398b59dd1df", - "sha256:1635fd110e8d85d55237ab316b5b011de701ea0f29d07611174a1b42f1444741", - "sha256:184c5108a2aca3c5b3d3bf9395d50893a7ab82a38004c8f61c258d4428e80206", - "sha256:18aeb1bf9a78867dc38b259769503436b7c72f7a1f1f4c93ff9a17de54319b27", - "sha256:1d4c7e777c441b20e32f52bd377e0c409713e8bb1386e1099c2415f26e479595", - "sha256:1e2722cc9fbb45d9b87631ac70924c11d3a401b2d7f410cc0e3bbf249f2dca62", - "sha256:1fe35611261b29bd1de0070f0b2f47cb6ff71fa6595c077e42bd0c419fa27b98", - "sha256:28c119d996beec18c05208a8bd78cbe4007878c6dd15091efb73a30e90539696", - "sha256:326c013efe8048858a6d312ddd31d56e468118ad4cdeda36c719bf5bb6192290", - "sha256:40df9b996c2b73138957fe23a16a4f0ba614f4c0efce1e9406a184b6d07fa3a9", - "sha256:42f8152b8dbc4fe7d96729ec2b99c7097d656dc1213a3229ca5383f973a5ed6d", - "sha256:49a183be227561de579b4a36efbb21b3eab9651dd81b1858589f796549873dd6", - "sha256:4fb147e7a67ef577a588a0e2c17b6db51dda102c71de36f8549b6816a96e1867", - "sha256:50550eb667afee136e9a77d6dc71ae76a44df8b3e51e41b77f6de2932bfe0f47", - "sha256:510c9deebc5c0225e8c96813043e62b680ba2f9c50a08d3724c7f28a747d1486", - "sha256:5773183b6446b2c99bb77e77595dd486303b4faab2b086e7b17bc6bef28865f6", - "sha256:596106435fa6ad000c2991a98fa58eeb8656ef2325d7e158344fb33864ed87e3", - "sha256:6965a7bc3cf88e5a1c3bd2e0b5c22f8d677dc88a455344035f03399034eb3007", - "sha256:69b023b2b4daa7548bcfbd4aa3da05b3a74b772db9e23b982788168117739938", - "sha256:6c22bec3fbe2524cde73d7ada88f6566758a8f7227bfbf93a408a9d86bcc12a0", - "sha256:704219a11b772aea0d8ecd7058d0082713c3562b4e271b849ad7dc4a5c90c13c", - "sha256:7e07cbde391ba96ab58e532ff4803f79c4129397514e1413a7dc761ccd755735", - "sha256:81e0b275a9ecc9c0c0c07b4b90ba548307583c125f54d5b6946cfee6360c733d", - "sha256:855fb52b0dc35af121542a76b9a84f8d1cd886ea97c84703eaa6d88e37a2ad28", - "sha256:8d4e9c88387b0f5c7d5f281e55304de64cf7f9c0021a3525bd3b1c542da3b0e4", - "sha256:9046c58c4395dff28dd494285c82ba00b546adfc7ef001486fbf0324bc174fba", - "sha256:9eb6caa9a297fc2c2fb8862bc5370d0303ddba53ba97e71f08023b6cd73d16a8", - "sha256:a08c6f0fe150303c1c6b71ebcd7213c2858041a7e01975da3a99aed1e7a378ef", - "sha256:a0cd17c15d3bb3fa06978b4e8958dcdc6e0174ccea823003a106c7d4d7899ac5", - "sha256:afd7e57eddb1a54f0f1a974bc4391af8bcce0b444685d936840f125cf046d5bd", - "sha256:b1275ad35a5d18c62a7220633c913e1b42d44b46ee12554e5fd39c70a243d6a3", - "sha256:b786eecbdf8499b9ca1d697215862083bd6d2a99965554781d0d8d1ad31e13a0", - "sha256:ba336e390cd8e4d1739f42dfe9bb83a3cc2e80f567d8805e11b46f4a943f5515", - "sha256:baa90d3f661d43131ca170712d903e6295d1f7a0f595074f151c0aed377c9b9c", - "sha256:bc1bf2925a1ecd43da378f4db9e4f799775d6367bdb94671027b73b393a7c42c", - "sha256:bd4af7373a854424dabd882decdc5579653d7868b8fb26dc7d0e99f823aa5924", - "sha256:bf07ee2fef7014951eeb99f56f39c9bb4af143d8aa3c21b1677805985307da34", - "sha256:bfdf460b1736c775f2ba9f6a92bca30bc2095067b8a9d77876d1fad6cc3b4a43", - "sha256:c8098ddcc2a85b61647b2590f825f3db38891662cfc2fc776415143f599bb859", - "sha256:d2b04aac4d386b172d5b9692e2d2da8de7bfb6c387fa4f801fbf6fb2e6ba4673", - "sha256:d483d2cdf104e7c9fa60c544d92981f12ad66a457afae824d146093b8c294c54", - "sha256:d858aa552c999bc8a8d57426ed01e40bef403cd8ccdd0fc5f6f04a00414cac2a", - "sha256:e7d73685e87afe9f3b36c799222440d6cf362062f78be1013661b00c5c6f678b", - "sha256:f003ed9ad21d6a4713f0a9b5a7a0a79e08dd0f221aff4525a2be4c346ee60aab", - "sha256:f22ac1c3cac4dbc50079e965eba2c1058622631e526bd9afd45fedd49ba781fa", - "sha256:faca3bdcf85b2fc05d06ff3fbc1f83e1391b3e724afa3feba7d13eeab355484c", - "sha256:fca0e3a251908a499833aa292323f32437106001d436eca0e6e7833256674585", - "sha256:fd1592b3fdf65fff2ad0004b5e363300ef59ced41c2e6b3a99d4089fa8c5435d", - "sha256:fd66fc5d0da6d9815ba2cebeb4205f95818ff4b79c3ebe268e75d961704af52f" + "sha256:01179a4a8559ab5de078078f37e5c1a30d76bb88519906844fd7bdea1b7729ff", + "sha256:0833f8694549e586547b576dcfaba4a6b55b9e96098b36cdc7ebefe667dfed48", + "sha256:0a9a2848a5b7feac301353437eb7d5957887edbf81d56e903999a75a3d743086", + "sha256:0b69e4ce7a131fe56b7e4d770c67429700908fc0752af059838b1cfb41960e4e", + "sha256:0ffe8360bab4910ef1b9e87fb812d8bc0a308b0d0eef8c8f44e0254ab3b07133", + "sha256:11d8f3dd2b9c1207dcaf2ee0bbbfd5991f571186ec9cc78427ba5bd32afae4b5", + "sha256:17e311b6c678207928d649faa7cb0d7b4c26a0ba73d41e99c4fff6b6c3276484", + "sha256:1e2120ef853f59c7419231f3bf4e7021f1b936f6ebd222406c3b60212205d2ee", + "sha256:1f71ea527786de97d1a0cc0eacd1defc0985dcf6b3f17bb77dcfc8c34bec4dc5", + "sha256:23502f431948090f597378482b4812b0caae32c22213aecf3b55325e049a6c68", + "sha256:24471b829b3bf607e04e88d79542a9d48bb037c2267d7927a874e6c205ca7e9a", + "sha256:29717114e51c84ddfba879543fb232a6ed60086602313ca38cce623c1d62cfbf", + "sha256:2e99c6826ffa974fe6e27cdb5ed0021786b03fc98e5ee3c5bfe1fd5015f42b99", + "sha256:39693e1f8320ae4f43943590b49779ffb98acb81f788220ea932a6b6c51004d8", + "sha256:3ad2a3decf9aaba3d29c8f537ac4b243e36bef957511b4766cb0057d32b0be85", + "sha256:3b1fdb9dc17f5a7677423d508ab4f243a726dea51fa5e70992e59a7411c89d19", + "sha256:41e4e3953a79407c794916fa277a82531dd93aad34e29c2a514c2c0c5fe971cc", + "sha256:43fa96a3ca0d6b1812e01ced1044a003533c47f6ee8aca31724f78e93ccc089a", + "sha256:50187695423ffe49e2deacb8cd10510bc361faac997de9efef88badc3bb9e2d1", + "sha256:5ac9328ec4831237bec75defaf839f7d4564be1e6b25ac710bd1a96321cc8317", + "sha256:5d225db5a45f21e78dd9358e58a98702a0302f2659a3c6cd320564b75b86f47c", + "sha256:6395c297d42274772abc367baaa79683958044e5d3835486c16da75d2a694631", + "sha256:688ba32a1cffef67fd2e9398a2efebaea461578b0923624778664cc1c914db5d", + "sha256:68ccc6023a3400877818152ad9a1033e3db8625d899c72eacb5a668902e4d652", + "sha256:70b189594dbe54f75ab3a1acec5f1e3faa7e8cf2f1e08d9b561cb41b845f69d5", + "sha256:797b4f722ffa07cc8d62053e4cff1486fa6dc094105d13fea7b1de7d8bf71c9e", + "sha256:7c36280e6fb8385e520936c3cb3b8042851904eba0e58d277dca80a5cfed590b", + "sha256:7e7401d0de89a9a855c839bc697c079a4af81cf878373abd7dc625847d25cbd8", + "sha256:80bab7bfc629882493af4aa31a4cfa43a4c57c83813253626916b8c7ada83476", + "sha256:82d09873e40955485746739bcb8b4586983670466c23382c19cffecbf1fd8706", + "sha256:8388ee1976c416731879ac16da0aff3f63b286ffdd57cdeb95f3f2e085687563", + "sha256:8824b5a04a04a047e72eea5cec3bc266db09e35de6bdfe34c9436ac5ee27d237", + "sha256:8b9c7197f7cb2738065c481a0461e50ad02f18c78cd75775628afb4d7137fb3b", + "sha256:9056c1ecd25795207ad294bcf39f2db3d845767be0ea6e6a34d856f006006083", + "sha256:936d68689298c36b53b29f23c6dbb74de12b4ac12ca6cfe0e047bedceea56180", + "sha256:9b22676e8097e9e22e36d6b7bda33190d0d400f345f23d4065d48f4ca7ae0425", + "sha256:a4d3091415f010369ae4ed1fc6b79def9416358877534caf6a0fdd2146c87a3e", + "sha256:a8786accb172bd8afb8be14490a16625cbc387036876ab6ba70912730faf8e1f", + "sha256:a9f8c2e67970f13b16084e04f134610fd1d374bf477b17ec1599185cf611d725", + "sha256:bc2fa7c6b47d6bc618dd7fb02ef6fdedb1090ec036abab80d4681424b84c1183", + "sha256:c70c95198c015b85feafc136515252a261a84561b7b1d51e3384e0655ddf25ab", + "sha256:cc1c1159b3d456576af7a3e4d1ba7e6924cb39de8f67111c735f6fc832082774", + "sha256:ce826d6ef20b1bc864f0a68340c8b3287705cae2f8b4b1d932177dcc76721725", + "sha256:d584d9ec91ad65861cc08d42e834324ef890a082e591037abe114850ff7bbc3e", + "sha256:d7fded462629cfa4b685c5416b949ebad6cec74af5e2d42905d41e257e0869f5", + "sha256:d84a1718ee396f54f3a086ea0a66d8e552b2ab2017ef8b420e92edbc841c352d", + "sha256:d8e03406cac8513435335dbab54c0d385e4a49e4945d2909a581c83647ca0290", + "sha256:e10ce637b18caea04431ce14fabcf5c64a1c61ec9c56b071a4b7ca131ca52d44", + "sha256:ec031d5d2feb36d1d1a24380e4db6d43695f3748343d99434e6f5f9156aaa2ed", + "sha256:ef6107725bd54b262d6dedcc2af448a266975032bc85ef0172c5f059da6325b4", + "sha256:efdca5630322a10774e8e98e1af481aad470dd62c3170801852d752aa7a783ba", + "sha256:f753120cb8181e736c57ef7636e83f31b9c0d1722c516f7e86cf15b7aa57ff12", + "sha256:ff3824dc5261f50c9b0dfb3be22b4567a6f938ccce4587b38952d85fd9e9afe4" ], - "markers": "python_version >= '3.6'", - "version": "==6.0.1" + "markers": "python_version >= '3.8'", + "version": "==6.0.2" }, "ragas": { "hashes": [ diff --git a/cleanup.py b/cleanup.py index c32d507..215fea0 100644 --- a/cleanup.py +++ b/cleanup.py @@ -5,9 +5,11 @@ load_dotenv(override=True, dotenv_path=".env.testing") + MONGO_URI = os.environ["MONGO_URI"] CONFIG_DB = os.environ["CONFIG_DB"] CONFIG_KB_COL = os.environ["CONFIG_KB_COL"] +print(f"CONFIG_DB: {CONFIG_DB}") kb_names = ["Sentence", "Semantic", "Markdown"] def drop_all_knowledge_bases(): diff --git a/evals.py b/evals.py index 779ec9e..e56113e 100644 --- a/evals.py +++ b/evals.py @@ -3,12 +3,12 @@ from ragas import evaluate from ragas.metrics import answer_relevancy, faithfulness, context_precision, context_recall, context_entity_recall, answer_similarity, answer_correctness -import eval_pg_utils as pg -import eval_utils as utils +import db.eval_pg_utils as pg +import db.eval_utils as utils -from server import UserQuery, post_query +# from server import UserQuery, post_query -import app_logger as log +import db.app_logger as log # called within the server /api/query route def store_running_eval_data(chatbot_id, query, response): diff --git a/pipeline/hybrid_search/vector.py b/pipeline/hybrid_search/vector.py index d84ffe4..e8b8312 100644 --- a/pipeline/hybrid_search/vector.py +++ b/pipeline/hybrid_search/vector.py @@ -21,17 +21,17 @@ # "interface" functions -def write_to_db(db_name, file_path): - if not os.path.exists(file_path): - log.debug(f"vector.py: write_to_db - invalid file_path {file_path}") - return +# def write_to_db(db_name, file_path): +# if not os.path.exists(file_path): +# log.debug(f"vector.py: write_to_db - invalid file_path {file_path}") +# return - if environment == 'local': - write_local(db_name, file_path) - elif environment == 'mongoatlas': - write_mongoAtlas(db_name, file_path) - else: - write_prod(db_name, file_path) +# if environment == 'local': +# write_local(db_name, file_path) +# elif environment == 'mongoatlas': +# write_mongoAtlas(db_name, file_path) +# else: +# write_prod(db_name, file_path) @@ -75,12 +75,8 @@ def read_local(db_name, top_k): # "non-local" functions (persist to docdb) -collection_name = 'vector_index' - -def mongo(): - mongo_uri = os.environ["MONGO_URI"] - mongodb_client = pymongo.MongoClient(mongo_uri) - return mongodb_client +COLLECTION_NAME = 'vector_index' +MONGO_URI = os.environ["MONGO_URI"] def write_prod(db_name, file_path): @@ -89,11 +85,11 @@ def write_prod(db_name, file_path): else: documents = SimpleDirectoryReader(input_files=[file_path]).load_data() - mongodb_client = mongo() + mongodb_client = pymongo.MongoClient(MONGO_URI) store = AWSDocDbVectorStore( mongodb_client, db_name=db_name, - collection_name=collection_name + collection_name=COLLECTION_NAME ) storage_context = StorageContext.from_defaults(vector_store=store) @@ -101,16 +97,16 @@ def write_prod(db_name, file_path): documents, storage_context=storage_context ) - # mongodb_client.close() - log.info(f"vector.py write_prod: {file_path} written to mongo {db_name}/{collection_name}") + mongodb_client.close() + log.info(f"vector.py write_prod: {file_path} written to mongo {db_name}/{COLLECTION_NAME}") def read_prod(db_name, top_k): - mongodb_client = mongo() + mongodb_client = pymongo.MongoClient(MONGO_URI) store = AWSDocDbVectorStore( mongodb_client, db_name=db_name, - collection_name=collection_name + collection_name=COLLECTION_NAME ) storage_context = StorageContext.from_defaults(vector_store=store) @@ -121,48 +117,18 @@ def read_prod(db_name, top_k): vector_retriever = vector_index.as_retriever(similarity_top_k=top_k) - # mongodb_client.close() - log.info(f"vector.py read_prod: vector retriever returned from mongo {db_name}/{collection_name}") + mongodb_client.close() + log.info(f"vector.py read_prod: vector retriever returned from mongo {db_name}/{COLLECTION_NAME}") return vector_retriever - # MongoAtlas functions -from llama_index.core.node_parser import SentenceSplitter - -def write_mongoAtlas(db_name, file_path): - if os.path.isdir(file_path): - documents = SimpleDirectoryReader(file_path).load_data() - else: - documents = SimpleDirectoryReader(input_files=[file_path]).load_data() - - nodes = SentenceSplitter(chunk_size=1024, chunk_overlap=20).get_nodes_from_documents(documents) - - mongodb_client = mongo() - store = MongoDBAtlasVectorSearch( - mongodb_client, - db_name=db_name, - collection_name=collection_name - ) - storage_context = StorageContext.from_defaults(vector_store=store) - - # VectorStoreIndex.from_documents( - # documents, storage_context=storage_context - # ) - VectorStoreIndex( - nodes, storage_context=storage_context - ) - - # mongodb_client.close() - log.info(f"vector.py write_mongoAtlas: {file_path} written to mongoAtlas {db_name}/{collection_name}") - - def read_mongoAtlas(db_name, top_k): - mongodb_client = mongo() + mongodb_client = pymongo.MongoClient(MONGO_URI) store = MongoDBAtlasVectorSearch( mongodb_client, db_name=db_name, - collection_name=collection_name + collection_name=COLLECTION_NAME ) storage_context = StorageContext.from_defaults(vector_store=store) @@ -174,5 +140,148 @@ def read_mongoAtlas(db_name, top_k): vector_retriever = vector_index.as_retriever(similarity_top_k=top_k) # mongodb_client.close() - log.info(f"vector.py read_mongoAtlas: vector retriever returned from mongoAtlas {db_name}/{collection_name}") - return vector_retriever \ No newline at end of file + log.info(f"vector.py read_mongoAtlas: vector retriever returned from mongoAtlas {db_name}/{COLLECTION_NAME}") + return vector_retriever + + +# def get_retriever(db_name, top_k): +# if environment == 'local': +# return read_local(db_name, top_k) +# elif environment == 'mongoatlas': +# return read_mongoAtlas(db_name, top_k) +# else: +# return read_prod(db_name, top_k) + + + + + +# # local functions (persist to disk) + +# def write_local(db_name, file_path): +# if os.path.isdir(file_path): +# documents = SimpleDirectoryReader(file_path).load_data() +# else: +# documents = SimpleDirectoryReader(input_files=[file_path]).load_data() + +# vector_index = VectorStoreIndex.from_documents(documents) +# vector_index.storage_context.persist(persist_dir=db_name) +# log.info(f"vector.py write_local: {file_path} persist to disk") + + + +# def read_local(db_name, top_k): +# vector_storage_context = StorageContext.from_defaults(persist_dir=db_name) + +# vector_index = load_index_from_storage(vector_storage_context) + +# vector_retriever = vector_index.as_retriever(similarity_top_k=top_k) +# log.info(f"vector.py read_local: vector retriever returned with top_k '{top_k}'") +# return vector_retriever + + + + +# # "non-local" functions (persist to docdb) + +# collection_name = 'vector_index' + +# def mongo(): +# mongo_uri = os.environ["MONGO_URI"] +# mongodb_client = pymongo.MongoClient(mongo_uri) +# return mongodb_client + + +# def write_prod(db_name, file_path): +# if os.path.isdir(file_path): +# documents = SimpleDirectoryReader(file_path).load_data() +# else: +# documents = SimpleDirectoryReader(input_files=[file_path]).load_data() + +# mongodb_client = mongo() +# store = AWSDocDbVectorStore( +# mongodb_client, +# db_name=db_name, +# collection_name=collection_name +# ) +# storage_context = StorageContext.from_defaults(vector_store=store) + +# VectorStoreIndex.from_documents( +# documents, storage_context=storage_context +# ) + +# # mongodb_client.close() +# log.info(f"vector.py write_prod: {file_path} written to mongo {db_name}/{collection_name}") + + +# def read_prod(db_name, top_k): +# mongodb_client = mongo() +# store = AWSDocDbVectorStore( +# mongodb_client, +# db_name=db_name, +# collection_name=collection_name +# ) +# storage_context = StorageContext.from_defaults(vector_store=store) + +# vector_index = VectorStoreIndex.from_vector_store( +# vector_store=store, +# storage_context=storage_context +# ) + +# vector_retriever = vector_index.as_retriever(similarity_top_k=top_k) + +# # mongodb_client.close() +# log.info(f"vector.py read_prod: vector retriever returned from mongo {db_name}/{collection_name}") +# return vector_retriever + + +# # MongoAtlas functions + +# from llama_index.core.node_parser import SentenceSplitter + +# def write_mongoAtlas(db_name, file_path): +# if os.path.isdir(file_path): +# documents = SimpleDirectoryReader(file_path).load_data() +# else: +# documents = SimpleDirectoryReader(input_files=[file_path]).load_data() + +# nodes = SentenceSplitter(chunk_size=1024, chunk_overlap=20).get_nodes_from_documents(documents) + +# mongodb_client = mongo() +# store = MongoDBAtlasVectorSearch( +# mongodb_client, +# db_name=db_name, +# collection_name=collection_name +# ) +# storage_context = StorageContext.from_defaults(vector_store=store) + +# # VectorStoreIndex.from_documents( +# # documents, storage_context=storage_context +# # ) +# VectorStoreIndex( +# nodes, storage_context=storage_context +# ) + +# # mongodb_client.close() +# log.info(f"vector.py write_mongoAtlas: {file_path} written to mongoAtlas {db_name}/{collection_name}") + + +# def read_mongoAtlas(db_name, top_k): +# mongodb_client = mongo() +# store = MongoDBAtlasVectorSearch( +# mongodb_client, +# db_name=db_name, +# collection_name=collection_name +# ) +# storage_context = StorageContext.from_defaults(vector_store=store) + +# vector_index = VectorStoreIndex.from_vector_store( +# vector_store=store, +# storage_context=storage_context +# ) + +# vector_retriever = vector_index.as_retriever(similarity_top_k=top_k) + +# # mongodb_client.close() +# log.info(f"vector.py read_mongoAtlas: vector retriever returned from mongoAtlas {db_name}/{collection_name}") +# return vector_retriever \ No newline at end of file diff --git a/pipeline/mongo_util.py b/pipeline/mongo_util.py index 063e5ca..3bf6d57 100644 --- a/pipeline/mongo_util.py +++ b/pipeline/mongo_util.py @@ -20,11 +20,12 @@ def get(db_name, db_collection, query=None, projection=None): def get_all(db_name, db_collection, query=None, projection=None): mongo = pymongo.MongoClient(mongo_uri) results = mongo[db_name][db_collection].find(query, projection) + results = list(results) mongo.close() - ar = [] - for result in results: - ar.append(result) - return ar + # ar = [] + # for result in results: + # ar.append(result) + return results def insert_one(db_name, db_collection, doc): diff --git a/routers/__init__.py b/routers/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/server.py b/server.py index 6d77537..363e549 100644 --- a/server.py +++ b/server.py @@ -73,12 +73,20 @@ async def upload_file(id: str, file: UploadFile=File(...)): # query route @app.post('/api/query') async def post_query(body: pq.QueryBody): - return pq.post_query(body) - -@app.get('/api/history') -async def get_evals(): - data = evals.get_chat_history() - return {"table_data": data} + response = pq.post_query(body) + # add evals stuff here + evals.store_running_eval_data( + body.chatbot_id, + body.query, + response + ) + + return response + +# @app.get('/api/history') +# async def get_evals(): +# data = evals.get_chat_history() +# return {"table_data": data} if __name__ == "__main__": import uvicorn diff --git a/util/__init__.py b/util/__init__.py new file mode 100644 index 0000000..e69de29