Update app.py
Browse files
app.py
CHANGED
@@ -1,3 +1,4 @@
|
|
|
|
1 |
import json
|
2 |
import logging
|
3 |
import os
|
@@ -94,4 +95,44 @@ def main():
|
|
94 |
init_chromadb()
|
95 |
|
96 |
if __name__ == '__main__':
|
97 |
-
main()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""
|
2 |
import json
|
3 |
import logging
|
4 |
import os
|
|
|
95 |
init_chromadb()
|
96 |
|
97 |
if __name__ == '__main__':
|
98 |
+
main()
|
99 |
+
"""
|
100 |
+
import chromadb
|
101 |
+
from llama_index.vector_stores.chroma import ChromaVectorStore
|
102 |
+
from llama_index.core import VectorStoreIndex, StorageContext, TextNode
|
103 |
+
from llama_index.core.indices.vector_store.retrievers import VectorIndexAutoRetriever
|
104 |
+
from llama_index.core.query_engine import RetrieverQueryEngine
|
105 |
+
from llama_index.embeddings.huggingface import HuggingFaceEmbedding
|
106 |
+
|
107 |
+
# Initialize ChromaDB client and collection
|
108 |
+
chroma_client = chromadb.HttpClient(host="localhost", port="8080", ssl=False)
|
109 |
+
chroma_collection = chroma_client.get_or_create_collection("example_collection")
|
110 |
+
|
111 |
+
# Define embedding function using HuggingFace
|
112 |
+
embed_model = HuggingFaceEmbedding(model_name="all-MiniLM-L6-v2")
|
113 |
+
|
114 |
+
# Initialize ChromaVectorStore with the collection
|
115 |
+
vector_store = ChromaVectorStore(chroma_collection=chroma_collection)
|
116 |
+
|
117 |
+
# Set up StorageContext and VectorStoreIndex
|
118 |
+
storage_context = StorageContext.from_defaults(vector_store=vector_store)
|
119 |
+
index = VectorStoreIndex(embed_model=embed_model, storage_context=storage_context)
|
120 |
+
|
121 |
+
# Define and load documents with embeddings
|
122 |
+
documents = [
|
123 |
+
{"text": "Your document text here", "embedding": [0.1, 0.2, 0.3]},
|
124 |
+
# Add more documents as needed
|
125 |
+
]
|
126 |
+
|
127 |
+
# Load documents into ChromaDB using VectorStoreIndex
|
128 |
+
index.from_documents(documents=documents)
|
129 |
+
|
130 |
+
# Initialize the AutoRetriever with VectorStoreIndex and VectorStoreInfo
|
131 |
+
auto_retriever = VectorIndexAutoRetriever(index)
|
132 |
+
|
133 |
+
# Set up the RetrieverQuery Engine with the AutoRetriever
|
134 |
+
query_engine = RetrieverQueryEngine(auto_retriever)
|
135 |
+
|
136 |
+
# Query documents using the RetrieverQuery Engine
|
137 |
+
response = query_engine.query("Your query here")
|
138 |
+
print(response)
|