Spaces:
Sleeping
Sleeping
made a ingest file
Browse files
ingest.py
CHANGED
|
@@ -8,4 +8,25 @@ service_context = ServiceContext.from_defaults(text_splitter=text_splitter)
|
|
| 8 |
|
| 9 |
index = VectorStoreIndex.from_documents(
|
| 10 |
documents, service_context=service_context
|
| 11 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
index = VectorStoreIndex.from_documents(
|
| 10 |
documents, service_context=service_context
|
| 11 |
+
)
|
| 12 |
+
|
| 13 |
+
from llama_index.query import QueryBuilder
|
| 14 |
+
|
| 15 |
+
# Define the query text
|
| 16 |
+
query_text = "How does the weather affect crop growth?"
|
| 17 |
+
|
| 18 |
+
# Preprocess the query text
|
| 19 |
+
query_builder = QueryBuilder(service_context)
|
| 20 |
+
query = query_builder.build_query(query_text)
|
| 21 |
+
|
| 22 |
+
# Search for similar documents or retrieve relevant information
|
| 23 |
+
results = index.search(query)
|
| 24 |
+
|
| 25 |
+
# Process the search results
|
| 26 |
+
for result in results:
|
| 27 |
+
document_id = result.document_id
|
| 28 |
+
score = result.score
|
| 29 |
+
document = documents[document_id]
|
| 30 |
+
# Process the retrieved document or display the relevant information
|
| 31 |
+
print(f"Document ID: {document_id}, Score: {score}")
|
| 32 |
+
print(f"Document Text: {document.text}")
|