persadian commited on
Commit
156dcb4
·
verified ·
1 Parent(s): 90f1840

Create query_crops.py

Browse files
Files changed (1) hide show
  1. crop_db/query_crops.py +17 -0
crop_db/query_crops.py ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import chromadb
2
+ from chromadb.utils.embedding_functions import SentenceTransformerEmbeddingFunction
3
+
4
+ client = chromadb.PersistentClient(path="crop_db")
5
+ embedder = SentenceTransformerEmbeddingFunction(model_name="all-MiniLM-L6-v2")
6
+ collection = client.get_collection(name="crop_data", embedding_function=embedder)
7
+
8
+ results = collection.query(
9
+ query_texts=["crops suitable for clay soil"],
10
+ n_results=3,
11
+ include=["documents", "metadatas"]
12
+ )
13
+
14
+ print("Top crop recommendations:")
15
+ for doc, meta in zip(results['documents'][0], results['metadatas'][0]):
16
+ print(f"- {doc}")
17
+ print(f" Region: {meta['region']} | Season: {meta['season']}\n")