Spaces:
Sleeping
Sleeping
angelesteban00
commited on
Commit
•
93c0f74
1
Parent(s):
b01f455
Update app.py
Browse files
app.py
CHANGED
@@ -15,19 +15,18 @@ import os
|
|
15 |
|
16 |
DESCRIPTION = """\
|
17 |
# RAG - MongoDB Atlas Vector Search & OpenAI
|
18 |
-
This app is designed to provide a simple chat where to improve the answer from OpenAI with private information located in MongoDB Atlas cluster
|
19 |
The JSON documents in MongoDB looks like:
|
20 |
-
```
|
21 |
{
|
22 |
"_id": {
|
23 |
"$oid": "657b1ffa30c8238be21fd930"
|
24 |
},
|
25 |
-
"text": "Alfred: Hi, can you explain to me how compression works in MongoDB? Bruce: Sure! MongoDB supports compression of data at rest. It uses either zlib or snappy compression algorithms at the collection level. When data is written, MongoDB compresses and stores it compressed. When data is read, MongoDB uncompresses it before returning it. Compression reduces storage space requirements
|
|
|
26 |
"embedding": [...
|
27 |
],
|
28 |
"source": "sample_files/chat_conversation.txt"
|
29 |
}
|
30 |
-
```
|
31 |
"""
|
32 |
|
33 |
def query_data(query,openai_api_key,mongo_uri):
|
|
|
15 |
|
16 |
DESCRIPTION = """\
|
17 |
# RAG - MongoDB Atlas Vector Search & OpenAI
|
18 |
+
This app is designed to provide a simple chat where to improve the answer from OpenAI with private information located in MongoDB Atlas cluster.<br>
|
19 |
The JSON documents in MongoDB looks like:
|
|
|
20 |
{
|
21 |
"_id": {
|
22 |
"$oid": "657b1ffa30c8238be21fd930"
|
23 |
},
|
24 |
+
"text": "Alfred: Hi, can you explain to me how compression works in MongoDB? <br>Bruce: Sure! MongoDB supports compression of data at rest. It uses either zlib or snappy compression algorithms at the collection level. When data is written, MongoDB compresses and stores it compressed. When data is read, MongoDB uncompresses it before returning it. Compression reduces storage space requirements.<br> Alfred: Interesting, that's helpful to know. Can you also tell me how indexes are stored in MongoDB? <br>Bruce: MongoDB indexes are stored in B-trees. The internal nodes of the B-trees contain keys that point to children nodes or leaf nodes. The leaf nodes contain references to the actual documents stored in the collection. Indexes are stored in memory and also written to disk. The in-memory B-trees provide fast access for queries using the index.
|
25 |
+
<br>Alfred: Ok that makes sense. Does MongoDB compress the indexes as well?<br>Bruce: Yes, MongoDB also compresses the index data using prefix compression. This compresses common prefixes in the index keys to save space. However, the compression is lightweight and focused on performance vs storage space. Index compression is enabled by default.<br>Alfred: Great, that's really helpful context on how indexes are handled. One last question - when I query on a non-indexed field, how does MongoDB actually perform the scanning?<br>Bruce: MongoDB performs a collection scan if a query does not use an index.\n\nIt will scan every document in the collection in memory and on disk to select the documents that match the query. This can be resource intensive for large collections without indexes, so indexing improves query performance.<br>Alfred: Thank you for the detailed explanations <br>Bruce, I really appreciate you taking the time to walk through how compression and indexes work under the hood in MongoDB. Very helpful!Bruce: You're very welcome! I'm glad I could explain the technical details clearly. Feel free to reach out if you have any other MongoDB questions.",
|
26 |
"embedding": [...
|
27 |
],
|
28 |
"source": "sample_files/chat_conversation.txt"
|
29 |
}
|
|
|
30 |
"""
|
31 |
|
32 |
def query_data(query,openai_api_key,mongo_uri):
|