5
You can use Mongo Atlas in 2 ways:
7
1. Only as a vector DB (and use local or another mongo for data storage)
8
In this case, you can set the following environment variable:
9
MONGO_ATLAS_CONNECTION_URI=mongo+srv://<username>:<password>@<cluster-domain>...
11
2. For both vector and data storage
12
In this case, you can set the following environment configuration:
13
LLMWareConfig().set_config("collection_db_uri", "mongo+srv://<username>:<password>@<cluster-domain>..."
15
This example demonstrates the 2nd approach
19
from llmware.configs import LLMWareConfig
20
from llmware.library import Library
21
from llmware.retrieval import Query
22
from llmware.setup import Setup
28
def using_mongo_atlas(mongo_atlas_connection_string):
30
LLMWareConfig().set_config("collection_db_uri", mongo_atlas_connection_string)
34
library_name = "test_mongo_atlas"
35
print(f"\n > Creating library {library_name}...")
37
library = Library().create_new_library(library_name)
38
print(f"\n > Loading the llmware Sample Files...")
40
sample_files_path = Setup().load_sample_files()
41
print(f"\n > Adding some files to the library...")
43
library.add_files(input_folder_path=os.path.join(sample_files_path, "Agreements"))
46
print(f"\n > Generating embedding vectors (using the 'mini-lm-sbert' model) and storing them (in 'Mongo Atlas')...")
47
library.install_new_embedding(embedding_model_name="mini-lm-sbert", vector_db="mongo_atlas")
50
print(f"\n > Running a query for 'Salary'...")
51
query_results = Query(library).semantic_query(query="salary", result_count=10, results_only=True)
53
print(f"\n\nResults for 'Salary' in {library_name}:\n")
54
for query_result in query_results:
56
"File: " + query_result["file_source"] + " (Page " + str(query_result["page_num"]) + "):\n" + query_result[
62
if __name__ == "__main__":
65
mongo_config = os.environ["MONGO_ATLAS_CONNECTION_URI"]
67
output = using_mongo_atlas(mongo_config)