demeter
Autonomous Hydroponic Intelligencegit clone https://github.com/maydayv7/demeter
backend/server/create-index.py (1523B)
1"""
2Script to create payload indexes for filtering in Qdrant.
3Run this ONCE to enable filtering by 'crop' and 'stage'.
4"""
5
6import sys
7import os
8
9# Add project root to path
10current_dir = os.path.dirname(os.path.abspath(__file__))
11project_root = os.path.abspath(os.path.join(current_dir, '../../'))
12sys.path.append(project_root)
13
14from Qdrant.Client import client
15from Qdrant.Store import COLLECTION_NAME
16from qdrant_client.http import models
17
18def create_indexes():
19 """Create keyword indexes for crop and stage fields"""
20
21 print(f"📑 Creating payload indexes for collection: {COLLECTION_NAME}")
22
23 try:
24 # Create index for 'crop' field
25 client.create_payload_index(
26 collection_name=COLLECTION_NAME,
27 field_name="crop",
28 field_schema=models.PayloadSchemaType.KEYWORD
29 )
30 print("✅ Index created for 'crop' field")
31
32 # Create index for 'stage' field
33 client.create_payload_index(
34 collection_name=COLLECTION_NAME,
35 field_name="stage",
36 field_schema=models.PayloadSchemaType.KEYWORD
37 )
38 print("✅ Index created for 'stage' field")
39
40 print("\n🎉 All indexes created successfully!")
41 print("You can now use filtered searches in your /search endpoint.")
42
43 except Exception as e:
44 print(f"❌ Error creating indexes: {e}")
45 print("\nNote: If indexes already exist, this is normal.")
46
47if __name__ == "__main__":
48 create_indexes()