File tree 4 files changed +56
-1
lines changed
4 files changed +56
-1
lines changed Original file line number Diff line number Diff line change @@ -32,4 +32,5 @@ def query(q):
32
32
33
33
query ("What are the effects of legislations surrounding emissions on the Australia coal market?" )
34
34
query ("What are China's plans with renewable energy?" )
35
- query ("Is there an export ban on Coal in Indonesia? Why?" )
35
+ query ("Is there an export ban on Coal in Indonesia? Why?" )
36
+ query ("Who are the main exporters of Coal to China? What is the role of Indonesia in this?" )
Original file line number Diff line number Diff line change 4
4
load_dotenv ()
5
5
6
6
documents = SimpleDirectoryReader ('news' ).load_data ()
7
+
7
8
index = GPTSimpleVectorIndex .from_documents (documents )
8
9
9
10
# save to disk
Original file line number Diff line number Diff line change
1
+ from llama_index import GPTChromaIndex , SimpleDirectoryReader
2
+ import chromadb
3
+
4
+ from dotenv import load_dotenv
5
+
6
+ load_dotenv ()
7
+ # https://docs.trychroma.com/embeddings
8
+ # create a Chroma vector store, by default operating purely in-memory
9
+ chroma_client = chromadb .Client ()
10
+
11
+ # create a collection
12
+ chroma_collection = chroma_client .create_collection ("newspieces" )
13
+ # https://docs.trychroma.com/api-reference
14
+ print (chroma_collection .count ())
15
+
16
+ documents = SimpleDirectoryReader ('news' ).load_data ()
17
+
18
+ index = GPTChromaIndex .from_documents (documents , chroma_collection = chroma_collection )
19
+ print (chroma_collection .count ())
20
+ print (chroma_collection .get ()['documents' ])
21
+ print (chroma_collection .get ()['metadatas' ])
22
+
23
+ index .save_to_disk ("newspieces.json" )
24
+
25
+ # During query time, the index uses Chroma to query for the top k
26
+ # most similar nodes, and synthesizes an answer from the retrieved nodes.
27
+
28
+ r = index .query ("Who are the main exporters of Coal to China? What is the role of Indonesia in this?" )
29
+ print (r )
Original file line number Diff line number Diff line change
1
+ {
2
+ "index_struct" : {
3
+ "__type__" : " chroma" ,
4
+ "__data__" : {
5
+ "index_id" : " 6c885f2c-9b0d-44b6-ad81-ce34ad3ccc87" ,
6
+ "summary" : null ,
7
+ "nodes_dict" : {},
8
+ "doc_id_dict" : {},
9
+ "embeddings_dict" : {}
10
+ }
11
+ },
12
+ "docstore" : {
13
+ "docs" : {},
14
+ "ref_doc_info" : {
15
+ "eba4909c-2870-445c-90a2-8f07c29c31ff" : {
16
+ "doc_hash" : " 1abedf1e096b34455d8e4cd5b65b87329a34b30e8ce3c6fabd000241522e5081"
17
+ },
18
+ "9b7ab721-a18f-4c48-b103-242c790390f6" : {
19
+ "doc_hash" : " e55b12ed31aceb1a6b09488c2686b3290405c6d682d19a0c3719f1502681f416"
20
+ }
21
+ }
22
+ },
23
+ "vector_store" : {}
24
+ }
You can’t perform that action at this time.
0 commit comments