| """ |
| AI Vectorization Engine (The Brain) |
| This script demonstrates how to pass the scraped data into OpenAI to create Vectors, |
| which are then stored in Pinecone for semantic search. |
| """ |
| import os |
| import json |
| |
| |
| |
|
|
| |
| |
| |
| |
|
|
| def vectorize_properties(json_file): |
| print("[*] Loading raw properties...") |
| try: |
| with open(json_file, 'r', encoding='utf-8') as f: |
| properties = json.load(f) |
| except FileNotFoundError: |
| print("[!] raw_properties.json not found. Run scraper first.") |
| return |
|
|
| vectors_to_upsert = [] |
|
|
| print("[*] Generating AI Embeddings via OpenAI...") |
| for idx, prop in enumerate(properties): |
| |
| ai_description = f"{prop['title']}. It is located in {prop['location']}. The price is {prop['price']}." |
| |
| |
| print(f" -> Vectorizing: {prop['title']}") |
| |
| """ |
| # REAL CODE: |
| response = openai_client.embeddings.create( |
| input=ai_description, |
| model="text-embedding-3-small" |
| ) |
| vector_data = response.data[0].embedding |
| """ |
| vector_data = [0.015, -0.022, 0.045] |
| |
| |
| vectors_to_upsert.append({ |
| "id": f"prop_{idx}", |
| "values": vector_data, |
| "metadata": { |
| "title": prop['title'], |
| "price": prop['price'], |
| "location": prop['location'], |
| "image": prop['image'] |
| } |
| }) |
|
|
| |
| print(f"[*] Uploading {len(vectors_to_upsert)} vectors to Pinecone...") |
| """ |
| # REAL CODE: |
| index.upsert(vectors=vectors_to_upsert) |
| """ |
| print("[+] Architecture Phase 2 Complete. Properties are now searchable via Semantic Search!") |
|
|
| def search_smart_match(user_query): |
| """ Example of how a user's quiz results are searched """ |
| print(f"\n[*] User searches for: '{user_query}'") |
| print("[*] Vectorizing user query...") |
| |
| print("[+] Returning top 10 AI matches...") |
|
|
| if __name__ == "__main__": |
| |
| dummy_data = [{"title": "شقة في زايد", "location": "Sheikh Zayed", "price": "5,000,000", "image": ""}] |
| with open('raw_properties.json', 'w', encoding='utf-8') as f: |
| json.dump(dummy_data, f) |
| |
| vectorize_properties('raw_properties.json') |
| search_smart_match("I want a quiet place near good schools in Zayed under 6M") |
|
|