| import chromadb | |
| from chromadb.utils.embedding_functions import SentenceTransformerEmbeddingFunction | |
| client = chromadb.PersistentClient(path="crop_db") | |
| embedder = SentenceTransformerEmbeddingFunction(model_name="all-MiniLM-L6-v2") | |
| collection = client.get_collection(name="crop_data", embedding_function=embedder) | |
| results = collection.query( | |
| query_texts=["crops suitable for clay soil"], | |
| n_results=3, | |
| include=["documents", "metadatas"] | |
| ) | |
| print("Top crop recommendations:") | |
| for doc, meta in zip(results['documents'][0], results['metadatas'][0]): | |
| print(f"- {doc}") | |
| print(f" Region: {meta['region']} | Season: {meta['season']}\n") |