angelesteban00 commited on
Commit
b2258b8
1 Parent(s): 93c0f74

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -2
app.py CHANGED
@@ -17,16 +17,27 @@ 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):
 
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
  {
22
  "_id": {
23
  "$oid": "657b1ffa30c8238be21fd930"
24
  },
25
+ "text": "
26
+ Alfred: Hi, can you explain to me how compression works in MongoDB?
27
+ 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.
28
+ Alfred: Interesting, that's helpful to know. Can you also tell me how indexes are stored in MongoDB?
29
+ 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.
30
+ Alfred: Ok that makes sense. Does MongoDB compress the indexes as well
31
+ 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.
32
+ 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?
33
+ Bruce: MongoDB performs a collection scan if a query does not use an index. It 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.
34
+ Alfred: Thank you for the detailed explanations
35
+ 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.",
36
  "embedding": [...
37
  ],
38
  "source": "sample_files/chat_conversation.txt"
39
  }
40
+ ```
41
  """
42
 
43
  def query_data(query,openai_api_key,mongo_uri):