Created
June 13, 2024 16:34
-
-
Save tspannhw/62fc723b2229abcd1237f3727c0f2e15 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "cells": [ | |
| { | |
| "cell_type": "markdown", | |
| "id": "be25dabd-2067-4860-a0c6-0acebcedde83", | |
| "metadata": {}, | |
| "source": [ | |
| "Find Incidents\n" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 1, | |
| "id": "a78115f6-f696-4481-8d11-1ff38d346329", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "name": "stderr", | |
| "output_type": "stream", | |
| "text": [ | |
| "/Users/timothyspann/Downloads/code/milvusvenv/lib/python3.12/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n", | |
| " from .autonotebook import tqdm as notebook_tqdm\n" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "import json\n", | |
| "import requests\n", | |
| "from pymilvus import model\n", | |
| "from pymilvus.model.dense import SentenceTransformerEmbeddingFunction" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 2, | |
| "id": "da706de1-53f2-4a08-8dea-e4820b3b557d", | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "import os\n", | |
| "from pymilvus import MilvusClient\n", | |
| "\n", | |
| "DIMENSION = 384 \n", | |
| "MILVUS_URL = \"http://192.168.1.163:19530\" \n", | |
| "COLLECTION_NAME = \"nyccollisions\"\n", | |
| "\n", | |
| "# -----------------------------------------------------------------------------\n", | |
| "# Connect to Milvus\n", | |
| "\n", | |
| "# Milvus Lite\n", | |
| "# milvus_client = MilvusClient(uri=\"streetcams.db\")\n", | |
| "\n", | |
| "# Local Docker Server\n", | |
| "milvus_client = MilvusClient( uri=MILVUS_URL )" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 6, | |
| "id": "f9c09843-2407-4fd7-be5a-652022a79890", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "name": "stderr", | |
| "output_type": "stream", | |
| "text": [ | |
| "/Users/timothyspann/Downloads/code/milvusvenv/lib/python3.12/site-packages/huggingface_hub/file_download.py:1132: FutureWarning: `resume_download` is deprecated and will be removed in version 1.0.0. Downloads always resume when possible. If you want to force a new download, use `force_download=True`.\n", | |
| " warnings.warn(\n" | |
| ] | |
| }, | |
| { | |
| "name": "stdout", | |
| "output_type": "stream", | |
| "text": [ | |
| "Hit: {'id': 4720812, 'distance': 0.0, 'entity': {'id': 4720812, 'crash': {'details': 'Crash occurred on JACKSON STREET with off street CHERRY STREET MANHATTAN, NY 10002 with lat/long 40.712208 -73.98072 at 0:02 on 2024-04-30T00:00:00.000 with vehicles Taxi and Bus including 0 injuries', 'on_street_name': 'JACKSON STREET', 'off_street_name': 'CHERRY STREET', 'crash_date': '2024-04-30T00:00:00.000', 'crash_time': '0:02', 'borough': 'MANHATTAN', 'zip_code': '10002', 'latitude': '40.712208', 'longitude': '-73.98072', 'location': 'JACKSON STREET MANHATTAN, NY 10002', 'number_of_persons_injured': '0', 'number_of_persons_killed': '0', 'number_of_pedestrians_injured': '0', 'number_of_pedestrians_killed': '0', 'number_of_cyclist_injured': '0', 'number_of_cyclist_killed': '0', 'number_of_motorist_injured': '0', 'number_of_motorist_killed': '0', 'contributing_factor_vehicle_1': 'Failure to Yield Right-of-Way', 'vehicle_type_code1': 'Taxi', 'contributing_factor_vehicle_2': 'Unspecified', 'vehicle_type_code2': 'Bus', 'cross_street_name': '', 'contributing_factor_vehicle_3': '', 'vehicle_type_code_3': '', 'contributing_factor_vehicle_4': '', 'vehicle_type_code_4': ''}}}\n", | |
| "Hit: {'id': 4721489, 'distance': 0.20554286241531372, 'entity': {'id': 4721489, 'crash': {'details': 'Crash occurred on 2 AVENUE with off street EAST 36 STREET MANHATTAN, NY 10016 with lat/long 40.74608 -73.974945 at 12:35 on 2024-05-01T00:00:00.000 with vehicles Taxi and Sedan including 0 injuries', 'on_street_name': '2 AVENUE', 'off_street_name': 'EAST 36 STREET', 'crash_date': '2024-05-01T00:00:00.000', 'crash_time': '12:35', 'borough': 'MANHATTAN', 'zip_code': '10016', 'latitude': '40.74608', 'longitude': '-73.974945', 'location': '2 AVENUE MANHATTAN, NY 10016', 'number_of_persons_injured': '0', 'number_of_persons_killed': '0', 'number_of_pedestrians_injured': '0', 'number_of_pedestrians_killed': '0', 'number_of_cyclist_injured': '0', 'number_of_cyclist_killed': '0', 'number_of_motorist_injured': '0', 'number_of_motorist_killed': '0', 'contributing_factor_vehicle_1': 'Unspecified', 'vehicle_type_code1': 'Taxi', 'contributing_factor_vehicle_2': 'Unspecified', 'vehicle_type_code2': 'Sedan', 'cross_street_name': '', 'contributing_factor_vehicle_3': '', 'vehicle_type_code_3': '', 'contributing_factor_vehicle_4': '', 'vehicle_type_code_4': ''}}}\n", | |
| "Hit: {'id': 4730512, 'distance': 0.20585159957408905, 'entity': {'id': 4730512, 'crash': {'details': 'Crash occurred on 2 AVENUE with off street EAST 116 STREET MANHATTAN, NY 10029 with lat/long 40.797 -73.93778 at 7:13 on 2024-06-04T00:00:00.000 with vehicles Taxi and Sedan including 1 injuries', 'on_street_name': '2 AVENUE', 'off_street_name': 'EAST 116 STREET', 'crash_date': '2024-06-04T00:00:00.000', 'crash_time': '7:13', 'borough': 'MANHATTAN', 'zip_code': '10029', 'latitude': '40.797', 'longitude': '-73.93778', 'location': '2 AVENUE MANHATTAN, NY 10029', 'number_of_persons_injured': '1', 'number_of_persons_killed': '0', 'number_of_pedestrians_injured': '0', 'number_of_pedestrians_killed': '0', 'number_of_cyclist_injured': '0', 'number_of_cyclist_killed': '0', 'number_of_motorist_injured': '1', 'number_of_motorist_killed': '0', 'contributing_factor_vehicle_1': 'Unspecified', 'vehicle_type_code1': 'Taxi', 'contributing_factor_vehicle_2': 'Unspecified', 'vehicle_type_code2': 'Sedan', 'cross_street_name': '', 'contributing_factor_vehicle_3': '', 'vehicle_type_code_3': '', 'contributing_factor_vehicle_4': '', 'vehicle_type_code_4': ''}}}\n", | |
| "Hit: {'id': 4728451, 'distance': 0.20982535183429718, 'entity': {'id': 4728451, 'crash': {'details': 'Crash occurred on AVENUE A with off street EAST 2 STREET MANHATTAN, NY 10009 with lat/long 40.72301 -73.98576 at 1:39 on 2024-05-25T00:00:00.000 with vehicles Taxi and Sedan including 0 injuries', 'on_street_name': 'AVENUE A', 'off_street_name': 'EAST 2 STREET', 'crash_date': '2024-05-25T00:00:00.000', 'crash_time': '1:39', 'borough': 'MANHATTAN', 'zip_code': '10009', 'latitude': '40.72301', 'longitude': '-73.98576', 'location': 'AVENUE A MANHATTAN, NY 10009', 'number_of_persons_injured': '0', 'number_of_persons_killed': '0', 'number_of_pedestrians_injured': '0', 'number_of_pedestrians_killed': '0', 'number_of_cyclist_injured': '0', 'number_of_cyclist_killed': '0', 'number_of_motorist_injured': '0', 'number_of_motorist_killed': '0', 'contributing_factor_vehicle_1': 'Driver Inattention/Distraction', 'vehicle_type_code1': 'Taxi', 'contributing_factor_vehicle_2': 'Unspecified', 'vehicle_type_code2': 'Sedan', 'cross_street_name': '', 'contributing_factor_vehicle_3': '', 'vehicle_type_code_3': '', 'contributing_factor_vehicle_4': '', 'vehicle_type_code_4': ''}}}\n", | |
| "Hit: {'id': 4722305, 'distance': 0.2128656506538391, 'entity': {'id': 4722305, 'crash': {'details': 'Crash occurred on 5 AVENUE with off street EAST 62 STREET MANHATTAN, NY 10065 with lat/long 40.76614 -73.97166 at 19:18 on 2024-05-05T00:00:00.000 with vehicles Taxi and Moped including 0 injuries', 'on_street_name': '5 AVENUE', 'off_street_name': 'EAST 62 STREET', 'crash_date': '2024-05-05T00:00:00.000', 'crash_time': '19:18', 'borough': 'MANHATTAN', 'zip_code': '10065', 'latitude': '40.76614', 'longitude': '-73.97166', 'location': '5 AVENUE MANHATTAN, NY 10065', 'number_of_persons_injured': '0', 'number_of_persons_killed': '0', 'number_of_pedestrians_injured': '0', 'number_of_pedestrians_killed': '0', 'number_of_cyclist_injured': '0', 'number_of_cyclist_killed': '0', 'number_of_motorist_injured': '0', 'number_of_motorist_killed': '0', 'contributing_factor_vehicle_1': 'Unspecified', 'vehicle_type_code1': 'Taxi', 'contributing_factor_vehicle_2': 'Unspecified', 'vehicle_type_code2': 'Moped', 'cross_street_name': '', 'contributing_factor_vehicle_3': '', 'vehicle_type_code_3': '', 'contributing_factor_vehicle_4': '', 'vehicle_type_code_4': ''}}}\n", | |
| "Hit: {'id': 4721491, 'distance': 0.2135135978460312, 'entity': {'id': 4721491, 'crash': {'details': 'Crash occurred on 2 AVENUE with off street EAST 57 STREET MANHATTAN, NY 10022 with lat/long 40.759308 -73.9653 at 3:30 on 2024-05-02T00:00:00.000 with vehicles Taxi and including 0 injuries', 'on_street_name': '2 AVENUE', 'off_street_name': 'EAST 57 STREET', 'crash_date': '2024-05-02T00:00:00.000', 'crash_time': '3:30', 'borough': 'MANHATTAN', 'zip_code': '10022', 'latitude': '40.759308', 'longitude': '-73.9653', 'location': '2 AVENUE MANHATTAN, NY 10022', 'number_of_persons_injured': '0', 'number_of_persons_killed': '0', 'number_of_pedestrians_injured': '0', 'number_of_pedestrians_killed': '0', 'number_of_cyclist_injured': '0', 'number_of_cyclist_killed': '0', 'number_of_motorist_injured': '0', 'number_of_motorist_killed': '0', 'contributing_factor_vehicle_1': 'Driver Inattention/Distraction', 'vehicle_type_code1': 'Taxi', 'contributing_factor_vehicle_2': 'Unspecified', 'vehicle_type_code2': '', 'cross_street_name': '', 'contributing_factor_vehicle_3': '', 'vehicle_type_code_3': '', 'contributing_factor_vehicle_4': '', 'vehicle_type_code_4': ''}}}\n", | |
| "Hit: {'id': 4725890, 'distance': 0.21412880718708038, 'entity': {'id': 4725890, 'crash': {'details': 'Crash occurred on 3 AVENUE with off street , NY with lat/long 40.77043 -73.96012 at 22:58 on 2024-05-17T00:00:00.000 with vehicles Taxi and Station Wagon/Sport Utility Vehicle including 0 injuries', 'on_street_name': '3 AVENUE', 'off_street_name': '', 'crash_date': '2024-05-17T00:00:00.000', 'crash_time': '22:58', 'borough': '', 'zip_code': '', 'latitude': '40.77043', 'longitude': '-73.96012', 'location': '3 AVENUE , NY ', 'number_of_persons_injured': '0', 'number_of_persons_killed': '0', 'number_of_pedestrians_injured': '0', 'number_of_pedestrians_killed': '0', 'number_of_cyclist_injured': '0', 'number_of_cyclist_killed': '0', 'number_of_motorist_injured': '0', 'number_of_motorist_killed': '0', 'contributing_factor_vehicle_1': 'Failure to Yield Right-of-Way', 'vehicle_type_code1': 'Taxi', 'contributing_factor_vehicle_2': 'Unspecified', 'vehicle_type_code2': 'Station Wagon/Sport Utility Vehicle', 'cross_street_name': '', 'contributing_factor_vehicle_3': '', 'vehicle_type_code_3': '', 'contributing_factor_vehicle_4': '', 'vehicle_type_code_4': ''}}}\n", | |
| "Hit: {'id': 4724724, 'distance': 0.2142183482646942, 'entity': {'id': 4724724, 'crash': {'details': 'Crash occurred on 2 AVENUE with off street EAST 94 STREET MANHATTAN, NY 10128 with lat/long 40.78294 -73.948044 at 4:53 on 2024-05-15T00:00:00.000 with vehicles Taxi and Sedan including 1 injuries', 'on_street_name': '2 AVENUE', 'off_street_name': 'EAST 94 STREET', 'crash_date': '2024-05-15T00:00:00.000', 'crash_time': '4:53', 'borough': 'MANHATTAN', 'zip_code': '10128', 'latitude': '40.78294', 'longitude': '-73.948044', 'location': '2 AVENUE MANHATTAN, NY 10128', 'number_of_persons_injured': '1', 'number_of_persons_killed': '0', 'number_of_pedestrians_injured': '0', 'number_of_pedestrians_killed': '0', 'number_of_cyclist_injured': '0', 'number_of_cyclist_killed': '0', 'number_of_motorist_injured': '1', 'number_of_motorist_killed': '0', 'contributing_factor_vehicle_1': 'Unspecified', 'vehicle_type_code1': 'Taxi', 'contributing_factor_vehicle_2': 'Unspecified', 'vehicle_type_code2': 'Sedan', 'cross_street_name': '', 'contributing_factor_vehicle_3': 'Unspecified', 'vehicle_type_code_3': 'Sedan', 'contributing_factor_vehicle_4': 'Unspecified', 'vehicle_type_code_4': 'Sedan'}}}\n", | |
| "Hit: {'id': 4725409, 'distance': 0.21584032475948334, 'entity': {'id': 4725409, 'crash': {'details': 'Crash occurred on EAST 7 STREET with off street AVENUE B MANHATTAN, NY 10009 with lat/long 40.72507 -73.98122 at 3:15 on 2024-05-16T00:00:00.000 with vehicles Taxi and including 2 injuries', 'on_street_name': 'EAST 7 STREET', 'off_street_name': 'AVENUE B', 'crash_date': '2024-05-16T00:00:00.000', 'crash_time': '3:15', 'borough': 'MANHATTAN', 'zip_code': '10009', 'latitude': '40.72507', 'longitude': '-73.98122', 'location': 'EAST 7 STREET MANHATTAN, NY 10009', 'number_of_persons_injured': '2', 'number_of_persons_killed': '0', 'number_of_pedestrians_injured': '0', 'number_of_pedestrians_killed': '0', 'number_of_cyclist_injured': '0', 'number_of_cyclist_killed': '0', 'number_of_motorist_injured': '2', 'number_of_motorist_killed': '0', 'contributing_factor_vehicle_1': 'Driver Inattention/Distraction', 'vehicle_type_code1': 'Taxi', 'contributing_factor_vehicle_2': 'Unspecified', 'vehicle_type_code2': '', 'cross_street_name': '', 'contributing_factor_vehicle_3': '', 'vehicle_type_code_3': '', 'contributing_factor_vehicle_4': '', 'vehicle_type_code_4': ''}}}\n", | |
| "Hit: {'id': 4726553, 'distance': 0.2202243059873581, 'entity': {'id': 4726553, 'crash': {'details': 'Crash occurred on AVENUE A with off street EAST 3 STREET MANHATTAN, NY 10009 with lat/long 40.723648 -73.98529 at 1:31 on 2024-05-19T00:00:00.000 with vehicles Taxi and Taxi including 1 injuries', 'on_street_name': 'AVENUE A', 'off_street_name': 'EAST 3 STREET', 'crash_date': '2024-05-19T00:00:00.000', 'crash_time': '1:31', 'borough': 'MANHATTAN', 'zip_code': '10009', 'latitude': '40.723648', 'longitude': '-73.98529', 'location': 'AVENUE A MANHATTAN, NY 10009', 'number_of_persons_injured': '1', 'number_of_persons_killed': '0', 'number_of_pedestrians_injured': '0', 'number_of_pedestrians_killed': '0', 'number_of_cyclist_injured': '0', 'number_of_cyclist_killed': '0', 'number_of_motorist_injured': '1', 'number_of_motorist_killed': '0', 'contributing_factor_vehicle_1': 'Driver Inattention/Distraction', 'vehicle_type_code1': 'Taxi', 'contributing_factor_vehicle_2': 'Unspecified', 'vehicle_type_code2': 'Taxi', 'cross_street_name': '', 'contributing_factor_vehicle_3': 'Unspecified', 'vehicle_type_code_3': 'Sedan', 'contributing_factor_vehicle_4': '', 'vehicle_type_code_4': ''}}}\n", | |
| "Hit: {'id': 4724052, 'distance': 0.2203208953142166, 'entity': {'id': 4724052, 'crash': {'details': 'Crash occurred on EAST 161 STREET with off street , NY with lat/long 40.825577 -73.918465 at 6:02 on 2024-05-08T00:00:00.000 with vehicles Taxi and Dump including 0 injuries', 'on_street_name': 'EAST 161 STREET', 'off_street_name': '', 'crash_date': '2024-05-08T00:00:00.000', 'crash_time': '6:02', 'borough': '', 'zip_code': '', 'latitude': '40.825577', 'longitude': '-73.918465', 'location': 'EAST 161 STREET , NY ', 'number_of_persons_injured': '0', 'number_of_persons_killed': '0', 'number_of_pedestrians_injured': '0', 'number_of_pedestrians_killed': '0', 'number_of_cyclist_injured': '0', 'number_of_cyclist_killed': '0', 'number_of_motorist_injured': '0', 'number_of_motorist_killed': '0', 'contributing_factor_vehicle_1': 'Passing Too Closely', 'vehicle_type_code1': 'Taxi', 'contributing_factor_vehicle_2': 'Unspecified', 'vehicle_type_code2': 'Dump', 'cross_street_name': '', 'contributing_factor_vehicle_3': '', 'vehicle_type_code_3': '', 'contributing_factor_vehicle_4': '', 'vehicle_type_code_4': ''}}}\n", | |
| "Hit: {'id': 4730901, 'distance': 0.22279925644397736, 'entity': {'id': 4730901, 'crash': {'details': 'Crash occurred on EAST 42 STREET with off street 2 AVENUE MANHATTAN, NY 10017 with lat/long 40.749825 -73.972206 at 23:09 on 2024-06-02T00:00:00.000 with vehicles Taxi and Station Wagon/Sport Utility Vehicle including 1 injuries', 'on_street_name': 'EAST 42 STREET', 'off_street_name': '2 AVENUE', 'crash_date': '2024-06-02T00:00:00.000', 'crash_time': '23:09', 'borough': 'MANHATTAN', 'zip_code': '10017', 'latitude': '40.749825', 'longitude': '-73.972206', 'location': 'EAST 42 STREET MANHATTAN, NY 10017', 'number_of_persons_injured': '1', 'number_of_persons_killed': '0', 'number_of_pedestrians_injured': '0', 'number_of_pedestrians_killed': '0', 'number_of_cyclist_injured': '0', 'number_of_cyclist_killed': '0', 'number_of_motorist_injured': '1', 'number_of_motorist_killed': '0', 'contributing_factor_vehicle_1': 'Driver Inattention/Distraction', 'vehicle_type_code1': 'Taxi', 'contributing_factor_vehicle_2': 'Driver Inattention/Distraction', 'vehicle_type_code2': 'Station Wagon/Sport Utility Vehicle', 'cross_street_name': '', 'contributing_factor_vehicle_3': 'Unspecified', 'vehicle_type_code_3': 'Station Wagon/Sport Utility Vehicle', 'contributing_factor_vehicle_4': '', 'vehicle_type_code_4': ''}}}\n", | |
| "Hit: {'id': 4731406, 'distance': 0.22805020213127136, 'entity': {'id': 4731406, 'crash': {'details': 'Crash occurred on 1 AVENUE with off street EAST 100 STREET MANHATTAN, NY 10029 with lat/long 40.785805 -73.942856 at 7:45 on 2024-06-07T00:00:00.000 with vehicles Taxi and Sedan including 0 injuries', 'on_street_name': '1 AVENUE', 'off_street_name': 'EAST 100 STREET', 'crash_date': '2024-06-07T00:00:00.000', 'crash_time': '7:45', 'borough': 'MANHATTAN', 'zip_code': '10029', 'latitude': '40.785805', 'longitude': '-73.942856', 'location': '1 AVENUE MANHATTAN, NY 10029', 'number_of_persons_injured': '0', 'number_of_persons_killed': '0', 'number_of_pedestrians_injured': '0', 'number_of_pedestrians_killed': '0', 'number_of_cyclist_injured': '0', 'number_of_cyclist_killed': '0', 'number_of_motorist_injured': '0', 'number_of_motorist_killed': '0', 'contributing_factor_vehicle_1': 'Passing or Lane Usage Improper', 'vehicle_type_code1': 'Taxi', 'contributing_factor_vehicle_2': 'Unspecified', 'vehicle_type_code2': 'Sedan', 'cross_street_name': '', 'contributing_factor_vehicle_3': '', 'vehicle_type_code_3': '', 'contributing_factor_vehicle_4': '', 'vehicle_type_code_4': ''}}}\n", | |
| "Hit: {'id': 4728886, 'distance': 0.22811295092105865, 'entity': {'id': 4728886, 'crash': {'details': 'Crash occurred on EAST 96 STREET with off street LEXINGTON AVENUE MANHATTAN, NY 10128 with lat/long 40.785866 -73.950935 at 17:25 on 2024-05-28T00:00:00.000 with vehicles Taxi and Sedan including 0 injuries', 'on_street_name': 'EAST 96 STREET', 'off_street_name': 'LEXINGTON AVENUE', 'crash_date': '2024-05-28T00:00:00.000', 'crash_time': '17:25', 'borough': 'MANHATTAN', 'zip_code': '10128', 'latitude': '40.785866', 'longitude': '-73.950935', 'location': 'EAST 96 STREET MANHATTAN, NY 10128', 'number_of_persons_injured': '0', 'number_of_persons_killed': '0', 'number_of_pedestrians_injured': '0', 'number_of_pedestrians_killed': '0', 'number_of_cyclist_injured': '0', 'number_of_cyclist_killed': '0', 'number_of_motorist_injured': '0', 'number_of_motorist_killed': '0', 'contributing_factor_vehicle_1': 'Driver Inattention/Distraction', 'vehicle_type_code1': 'Taxi', 'contributing_factor_vehicle_2': 'Unspecified', 'vehicle_type_code2': 'Sedan', 'cross_street_name': '', 'contributing_factor_vehicle_3': '', 'vehicle_type_code_3': '', 'contributing_factor_vehicle_4': '', 'vehicle_type_code_4': ''}}}\n", | |
| "Hit: {'id': 4727876, 'distance': 0.22837969660758972, 'entity': {'id': 4727876, 'crash': {'details': 'Crash occurred on PARK AVENUE with off street EAST 57 STREET MANHATTAN, NY 10022 with lat/long 40.76161 -73.97076 at 18:17 on 2024-05-10T00:00:00.000 with vehicles Taxi and Bus including 1 injuries', 'on_street_name': 'PARK AVENUE', 'off_street_name': 'EAST 57 STREET', 'crash_date': '2024-05-10T00:00:00.000', 'crash_time': '18:17', 'borough': 'MANHATTAN', 'zip_code': '10022', 'latitude': '40.76161', 'longitude': '-73.97076', 'location': 'PARK AVENUE MANHATTAN, NY 10022', 'number_of_persons_injured': '1', 'number_of_persons_killed': '0', 'number_of_pedestrians_injured': '0', 'number_of_pedestrians_killed': '0', 'number_of_cyclist_injured': '0', 'number_of_cyclist_killed': '0', 'number_of_motorist_injured': '1', 'number_of_motorist_killed': '0', 'contributing_factor_vehicle_1': 'Unspecified', 'vehicle_type_code1': 'Taxi', 'contributing_factor_vehicle_2': 'Unspecified', 'vehicle_type_code2': 'Bus', 'cross_street_name': '', 'contributing_factor_vehicle_3': '', 'vehicle_type_code_3': '', 'contributing_factor_vehicle_4': '', 'vehicle_type_code_4': ''}}}\n", | |
| "Hit: {'id': 4729848, 'distance': 0.22925573587417603, 'entity': {'id': 4729848, 'crash': {'details': 'Crash occurred on EAST 47 STREET with off street PARK AVENUE MANHATTAN, NY 10172 with lat/long 40.7553 -73.97535 at 16:45 on 2024-05-26T00:00:00.000 with vehicles Taxi and including 3 injuries', 'on_street_name': 'EAST 47 STREET', 'off_street_name': 'PARK AVENUE', 'crash_date': '2024-05-26T00:00:00.000', 'crash_time': '16:45', 'borough': 'MANHATTAN', 'zip_code': '10172', 'latitude': '40.7553', 'longitude': '-73.97535', 'location': 'EAST 47 STREET MANHATTAN, NY 10172', 'number_of_persons_injured': '3', 'number_of_persons_killed': '0', 'number_of_pedestrians_injured': '0', 'number_of_pedestrians_killed': '0', 'number_of_cyclist_injured': '0', 'number_of_cyclist_killed': '0', 'number_of_motorist_injured': '3', 'number_of_motorist_killed': '0', 'contributing_factor_vehicle_1': 'Unspecified', 'vehicle_type_code1': 'Taxi', 'contributing_factor_vehicle_2': '', 'vehicle_type_code2': '', 'cross_street_name': '', 'contributing_factor_vehicle_3': '', 'vehicle_type_code_3': '', 'contributing_factor_vehicle_4': '', 'vehicle_type_code_4': ''}}}\n", | |
| "Hit: {'id': 4723889, 'distance': 0.23030193150043488, 'entity': {'id': 4723889, 'crash': {'details': 'Crash occurred on WEST 33 STREET with off street 7 AVENUE MANHATTAN, NY 10001 with lat/long 40.750317 -73.99112 at 23:38 on 2024-05-06T00:00:00.000 with vehicles Taxi and including 1 injuries', 'on_street_name': 'WEST 33 STREET', 'off_street_name': '7 AVENUE', 'crash_date': '2024-05-06T00:00:00.000', 'crash_time': '23:38', 'borough': 'MANHATTAN', 'zip_code': '10001', 'latitude': '40.750317', 'longitude': '-73.99112', 'location': 'WEST 33 STREET MANHATTAN, NY 10001', 'number_of_persons_injured': '1', 'number_of_persons_killed': '0', 'number_of_pedestrians_injured': '1', 'number_of_pedestrians_killed': '0', 'number_of_cyclist_injured': '0', 'number_of_cyclist_killed': '0', 'number_of_motorist_injured': '0', 'number_of_motorist_killed': '0', 'contributing_factor_vehicle_1': 'Failure to Yield Right-of-Way', 'vehicle_type_code1': 'Taxi', 'contributing_factor_vehicle_2': '', 'vehicle_type_code2': '', 'cross_street_name': '', 'contributing_factor_vehicle_3': '', 'vehicle_type_code_3': '', 'contributing_factor_vehicle_4': '', 'vehicle_type_code_4': ''}}}\n", | |
| "Hit: {'id': 4723311, 'distance': 0.23404504358768463, 'entity': {'id': 4723311, 'crash': {'details': 'Crash occurred on EAST 73 STREET with off street LEXINGTON AVENUE MANHATTAN, NY 10021 with lat/long 40.771107 -73.961716 at 2:39 on 2024-05-10T00:00:00.000 with vehicles Taxi and Station Wagon/Sport Utility Vehicle including 0 injuries', 'on_street_name': 'EAST 73 STREET', 'off_street_name': 'LEXINGTON AVENUE', 'crash_date': '2024-05-10T00:00:00.000', 'crash_time': '2:39', 'borough': 'MANHATTAN', 'zip_code': '10021', 'latitude': '40.771107', 'longitude': '-73.961716', 'location': 'EAST 73 STREET MANHATTAN, NY 10021', 'number_of_persons_injured': '0', 'number_of_persons_killed': '0', 'number_of_pedestrians_injured': '0', 'number_of_pedestrians_killed': '0', 'number_of_cyclist_injured': '0', 'number_of_cyclist_killed': '0', 'number_of_motorist_injured': '0', 'number_of_motorist_killed': '0', 'contributing_factor_vehicle_1': 'Driver Inattention/Distraction', 'vehicle_type_code1': 'Taxi', 'contributing_factor_vehicle_2': 'Driver Inattention/Distraction', 'vehicle_type_code2': 'Station Wagon/Sport Utility Vehicle', 'cross_street_name': '', 'contributing_factor_vehicle_3': '', 'vehicle_type_code_3': '', 'contributing_factor_vehicle_4': '', 'vehicle_type_code_4': ''}}}\n", | |
| "Hit: {'id': 4723878, 'distance': 0.234172061085701, 'entity': {'id': 4723878, 'crash': {'details': 'Crash occurred on WEST 30 STREET with off street 8 AVENUE MANHATTAN, NY 10001 with lat/long 40.74967 -73.99531 at 15:10 on 2024-05-04T00:00:00.000 with vehicles Taxi and Station Wagon/Sport Utility Vehicle including 0 injuries', 'on_street_name': 'WEST 30 STREET', 'off_street_name': '8 AVENUE', 'crash_date': '2024-05-04T00:00:00.000', 'crash_time': '15:10', 'borough': 'MANHATTAN', 'zip_code': '10001', 'latitude': '40.74967', 'longitude': '-73.99531', 'location': 'WEST 30 STREET MANHATTAN, NY 10001', 'number_of_persons_injured': '0', 'number_of_persons_killed': '0', 'number_of_pedestrians_injured': '0', 'number_of_pedestrians_killed': '0', 'number_of_cyclist_injured': '0', 'number_of_cyclist_killed': '0', 'number_of_motorist_injured': '0', 'number_of_motorist_killed': '0', 'contributing_factor_vehicle_1': 'Driver Inattention/Distraction', 'vehicle_type_code1': 'Taxi', 'contributing_factor_vehicle_2': 'Unspecified', 'vehicle_type_code2': 'Station Wagon/Sport Utility Vehicle', 'cross_street_name': '', 'contributing_factor_vehicle_3': '', 'vehicle_type_code_3': '', 'contributing_factor_vehicle_4': '', 'vehicle_type_code_4': ''}}}\n", | |
| "Hit: {'id': 4723528, 'distance': 0.23457074165344238, 'entity': {'id': 4723528, 'crash': {'details': 'Crash occurred on 2 AVENUE with off street EAST 58 STREET MANHATTAN, NY 10022 with lat/long 40.759983 -73.964806 at 20:50 on 2024-05-06T00:00:00.000 with vehicles Taxi and Bike including 1 injuries', 'on_street_name': '2 AVENUE', 'off_street_name': 'EAST 58 STREET', 'crash_date': '2024-05-06T00:00:00.000', 'crash_time': '20:50', 'borough': 'MANHATTAN', 'zip_code': '10022', 'latitude': '40.759983', 'longitude': '-73.964806', 'location': '2 AVENUE MANHATTAN, NY 10022', 'number_of_persons_injured': '1', 'number_of_persons_killed': '0', 'number_of_pedestrians_injured': '0', 'number_of_pedestrians_killed': '0', 'number_of_cyclist_injured': '1', 'number_of_cyclist_killed': '0', 'number_of_motorist_injured': '0', 'number_of_motorist_killed': '0', 'contributing_factor_vehicle_1': 'Traffic Control Disregarded', 'vehicle_type_code1': 'Taxi', 'contributing_factor_vehicle_2': 'Unspecified', 'vehicle_type_code2': 'Bike', 'cross_street_name': '', 'contributing_factor_vehicle_3': '', 'vehicle_type_code_3': '', 'contributing_factor_vehicle_4': '', 'vehicle_type_code_4': ''}}}\n" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "from pymilvus import connections\n", | |
| "from pymilvus import utility\n", | |
| "from pymilvus import FieldSchema, CollectionSchema, DataType, Collection\n", | |
| "import pprint\n", | |
| "\n", | |
| "model = SentenceTransformerEmbeddingFunction('all-MiniLM-L6-v2',device='cpu' )\n", | |
| "\n", | |
| "earlyincident = \"Crash occurred on JACKSON STREET with off street CHERRY STREET MANHATTAN, NY 10002 with lat/long 40.712208 -73.98072 at 0:02 on 2024-04-30T00:00:00.000 with vehicles Taxi and Bus including 0 injuries\"\n", | |
| "\n", | |
| "\n", | |
| "# Define search parameters\n", | |
| "search_params = {\n", | |
| " \"metric_type\": \"L2\",\n", | |
| " \"params\": {\"nprobe\": 16}\n", | |
| "}\n", | |
| "\n", | |
| "# Use first record as search record\n", | |
| "query_vector = [model(earlyincident)]\n", | |
| "\n", | |
| "# Execute the search on the 'vector' field\n", | |
| "search_results = milvus_client.search(\n", | |
| " COLLECTION_NAME,\n", | |
| " data=query_vector,\n", | |
| " filter='crash[\"vehicle_type_code1\"] in [\"Taxi\"]',\n", | |
| " output_fields=[\"id\", \"crash\"],\n", | |
| " search_params=search_params,\n", | |
| " limit=20\n", | |
| ")\n", | |
| "\n", | |
| "# Print search results\n", | |
| "for hits in search_results:\n", | |
| " for hit in hits:\n", | |
| " print(f\"Hit: {hit}\")\n" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 9, | |
| "id": "ebee15f3-9f5a-41ce-8ad2-19efce7d3231", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "name": "stdout", | |
| "output_type": "stream", | |
| "text": [ | |
| "Hit: {'id': 4720812, 'distance': 0.0, 'entity': {'id': 4720812, 'crash': {'details': 'Crash occurred on JACKSON STREET with off street CHERRY STREET MANHATTAN, NY 10002 with lat/long 40.712208 -73.98072 at 0:02 on 2024-04-30T00:00:00.000 with vehicles Taxi and Bus including 0 injuries', 'on_street_name': 'JACKSON STREET', 'off_street_name': 'CHERRY STREET', 'crash_date': '2024-04-30T00:00:00.000', 'crash_time': '0:02', 'borough': 'MANHATTAN', 'zip_code': '10002', 'latitude': '40.712208', 'longitude': '-73.98072', 'location': 'JACKSON STREET MANHATTAN, NY 10002', 'number_of_persons_injured': '0', 'number_of_persons_killed': '0', 'number_of_pedestrians_injured': '0', 'number_of_pedestrians_killed': '0', 'number_of_cyclist_injured': '0', 'number_of_cyclist_killed': '0', 'number_of_motorist_injured': '0', 'number_of_motorist_killed': '0', 'contributing_factor_vehicle_1': 'Failure to Yield Right-of-Way', 'vehicle_type_code1': 'Taxi', 'contributing_factor_vehicle_2': 'Unspecified', 'vehicle_type_code2': 'Bus', 'cross_street_name': '', 'contributing_factor_vehicle_3': '', 'vehicle_type_code_3': '', 'contributing_factor_vehicle_4': '', 'vehicle_type_code_4': ''}}}\n", | |
| "Hit: {'id': 4723655, 'distance': 0.19605156779289246, 'entity': {'id': 4723655, 'crash': {'details': 'Crash occurred on MONTGOMERY STREET with off street HENRY STREET MANHATTAN, NY 10002 with lat/long 40.713787 -73.98512 at 15:20 on 2024-05-11T00:00:00.000 with vehicles Sedan and Sedan including 0 injuries', 'on_street_name': 'MONTGOMERY STREET', 'off_street_name': 'HENRY STREET', 'crash_date': '2024-05-11T00:00:00.000', 'crash_time': '15:20', 'borough': 'MANHATTAN', 'zip_code': '10002', 'latitude': '40.713787', 'longitude': '-73.98512', 'location': 'MONTGOMERY STREET MANHATTAN, NY 10002', 'number_of_persons_injured': '0', 'number_of_persons_killed': '0', 'number_of_pedestrians_injured': '0', 'number_of_pedestrians_killed': '0', 'number_of_cyclist_injured': '0', 'number_of_cyclist_killed': '0', 'number_of_motorist_injured': '0', 'number_of_motorist_killed': '0', 'contributing_factor_vehicle_1': 'Driver Inexperience', 'vehicle_type_code1': 'Sedan', 'contributing_factor_vehicle_2': 'Unspecified', 'vehicle_type_code2': 'Sedan', 'cross_street_name': '', 'contributing_factor_vehicle_3': '', 'vehicle_type_code_3': '', 'contributing_factor_vehicle_4': '', 'vehicle_type_code_4': ''}}}\n", | |
| "Hit: {'id': 4723582, 'distance': 0.20148442685604095, 'entity': {'id': 4723582, 'crash': {'details': 'Crash occurred on 10 AVENUE with off street WEST 28 STREET MANHATTAN, NY 10001 with lat/long 40.750828 -74.00189 at 22:30 on 2024-05-09T00:00:00.000 with vehicles Sedan and Station Wagon/Sport Utility Vehicle including 0 injuries', 'on_street_name': '10 AVENUE', 'off_street_name': 'WEST 28 STREET', 'crash_date': '2024-05-09T00:00:00.000', 'crash_time': '22:30', 'borough': 'MANHATTAN', 'zip_code': '10001', 'latitude': '40.750828', 'longitude': '-74.00189', 'location': '10 AVENUE MANHATTAN, NY 10001', 'number_of_persons_injured': '0', 'number_of_persons_killed': '0', 'number_of_pedestrians_injured': '0', 'number_of_pedestrians_killed': '0', 'number_of_cyclist_injured': '0', 'number_of_cyclist_killed': '0', 'number_of_motorist_injured': '0', 'number_of_motorist_killed': '0', 'contributing_factor_vehicle_1': 'Driver Inattention/Distraction', 'vehicle_type_code1': 'Sedan', 'contributing_factor_vehicle_2': 'Unspecified', 'vehicle_type_code2': 'Station Wagon/Sport Utility Vehicle', 'cross_street_name': '', 'contributing_factor_vehicle_3': '', 'vehicle_type_code_3': '', 'contributing_factor_vehicle_4': '', 'vehicle_type_code_4': ''}}}\n", | |
| "Hit: {'id': 4721489, 'distance': 0.20554286241531372, 'entity': {'id': 4721489, 'crash': {'details': 'Crash occurred on 2 AVENUE with off street EAST 36 STREET MANHATTAN, NY 10016 with lat/long 40.74608 -73.974945 at 12:35 on 2024-05-01T00:00:00.000 with vehicles Taxi and Sedan including 0 injuries', 'on_street_name': '2 AVENUE', 'off_street_name': 'EAST 36 STREET', 'crash_date': '2024-05-01T00:00:00.000', 'crash_time': '12:35', 'borough': 'MANHATTAN', 'zip_code': '10016', 'latitude': '40.74608', 'longitude': '-73.974945', 'location': '2 AVENUE MANHATTAN, NY 10016', 'number_of_persons_injured': '0', 'number_of_persons_killed': '0', 'number_of_pedestrians_injured': '0', 'number_of_pedestrians_killed': '0', 'number_of_cyclist_injured': '0', 'number_of_cyclist_killed': '0', 'number_of_motorist_injured': '0', 'number_of_motorist_killed': '0', 'contributing_factor_vehicle_1': 'Unspecified', 'vehicle_type_code1': 'Taxi', 'contributing_factor_vehicle_2': 'Unspecified', 'vehicle_type_code2': 'Sedan', 'cross_street_name': '', 'contributing_factor_vehicle_3': '', 'vehicle_type_code_3': '', 'contributing_factor_vehicle_4': '', 'vehicle_type_code_4': ''}}}\n", | |
| "Hit: {'id': 4730512, 'distance': 0.20585159957408905, 'entity': {'id': 4730512, 'crash': {'details': 'Crash occurred on 2 AVENUE with off street EAST 116 STREET MANHATTAN, NY 10029 with lat/long 40.797 -73.93778 at 7:13 on 2024-06-04T00:00:00.000 with vehicles Taxi and Sedan including 1 injuries', 'on_street_name': '2 AVENUE', 'off_street_name': 'EAST 116 STREET', 'crash_date': '2024-06-04T00:00:00.000', 'crash_time': '7:13', 'borough': 'MANHATTAN', 'zip_code': '10029', 'latitude': '40.797', 'longitude': '-73.93778', 'location': '2 AVENUE MANHATTAN, NY 10029', 'number_of_persons_injured': '1', 'number_of_persons_killed': '0', 'number_of_pedestrians_injured': '0', 'number_of_pedestrians_killed': '0', 'number_of_cyclist_injured': '0', 'number_of_cyclist_killed': '0', 'number_of_motorist_injured': '1', 'number_of_motorist_killed': '0', 'contributing_factor_vehicle_1': 'Unspecified', 'vehicle_type_code1': 'Taxi', 'contributing_factor_vehicle_2': 'Unspecified', 'vehicle_type_code2': 'Sedan', 'cross_street_name': '', 'contributing_factor_vehicle_3': '', 'vehicle_type_code_3': '', 'contributing_factor_vehicle_4': '', 'vehicle_type_code_4': ''}}}\n" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "# Execute the search on the 'vector' field\n", | |
| "search_results = milvus_client.search(\n", | |
| " COLLECTION_NAME,\n", | |
| " data=query_vector,\n", | |
| " filter='crash[\"borough\"] like \"MANHATTAN\" && crash[\"vehicle_type_code1\"] in [\"Taxi\", \"Sedan\", \"Bus\"]',\n", | |
| " output_fields=[\"id\", \"crash\"],\n", | |
| " search_params=search_params,\n", | |
| " limit=5\n", | |
| ")\n", | |
| "\n", | |
| "# Print search results\n", | |
| "for hits in search_results:\n", | |
| " for hit in hits:\n", | |
| " print(f\"Hit: {hit}\")" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "id": "f54d2abd-11ab-4757-8dc4-2fc8d0691655", | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [] | |
| } | |
| ], | |
| "metadata": { | |
| "kernelspec": { | |
| "display_name": "Python 3 (ipykernel)", | |
| "language": "python", | |
| "name": "python3" | |
| }, | |
| "language_info": { | |
| "codemirror_mode": { | |
| "name": "ipython", | |
| "version": 3 | |
| }, | |
| "file_extension": ".py", | |
| "mimetype": "text/x-python", | |
| "name": "python", | |
| "nbconvert_exporter": "python", | |
| "pygments_lexer": "ipython3", | |
| "version": "3.12.3" | |
| } | |
| }, | |
| "nbformat": 4, | |
| "nbformat_minor": 5 | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment