Skip to content

Commit 2f0db9f

Browse files
committed
llama_index examples
1 parent 1fdf898 commit 2f0db9f

File tree

4 files changed

+56
-1
lines changed

4 files changed

+56
-1
lines changed

1_qna.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,5 @@ def query(q):
3232

3333
query("What are the effects of legislations surrounding emissions on the Australia coal market?")
3434
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?")

2_llama.py

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
load_dotenv()
55

66
documents = SimpleDirectoryReader('news').load_data()
7+
78
index = GPTSimpleVectorIndex.from_documents(documents)
89

910
# save to disk

2b_llama_chroma.py

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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)

newspieces.json

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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+
}

0 commit comments

Comments
 (0)