code: #!/usr/bin/env python
  
  import numpy as np
  import time
  import lancedb
  import pyarrow as pa
  import logging
  import sys
  
  logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
  
  def generate_random_data_vectors(num_vectors, dimension, offset=0):
      """
      Generate random data vectors.
  
      :param num_vectors: Number of vectors to generate.
      :param dimension: Dimension of each vector.
      :param offset: Offset for ID numbering.
      :return: List of dictionaries with vector and id.
      """
      return [{"vector": list(np.random.random(dimension)), "id": i} for i in range(1 + offset, num_vectors + 1 + offset)]
  
  
  def generate_random_vectors(num_vectors, dimension):
      """
      Generate random vectors using NumPy.
  
      :param num_vectors: Number of vectors to generate.
      :param dimension: Dimension of each vector.
      :return: NumPy array of random vectors.
      """
      return np.random.random((num_vectors, dimension))
  
  
  def main():
      # Parameters
      dimension = 1536
      num_vectors = 100000
      num_query_vectors = 20000
      top_k = 10
  
      db = lancedb.connect("./vectors.db")
  
      logging.info("Starting Generating Data")
      db_vectors = generate_random_data_vectors(num_vectors, dimension)
      query_vectors = generate_random_vectors(num_query_vectors, dimension)
      logging.info("Finished Generating Data")
  
      logging.info("Starting to insert data")
      table = db.create_table("vectors", data=db_vectors)
      for i in range(1, 10):
          logging.info(f"Starting to insert data with offset {i}")
          table.add(generate_random_data_vectors(num_vectors, dimension, offset=num_vectors * i))
          logging.info(f"Finished inserting data with offset {i}")
  
      logging.info("Finished inserting data")
  
      logging.info("Starting Queries")
      query_times = []
      for i, query_vector in enumerate(query_vectors):
          start_time = time.time()
          table.search(query_vector).limit(top_k)  # Adjust based on actual search method
          end_time = time.time()
          query_duration_ms = (end_time - start_time) * 1000
          query_times.append(query_duration_ms)
  
          if (i + 1) % 5000 == 0:
              logging.info(f"Iteration {i + 1}")
  
      percentiles = [50, 90, 95, 99]
      percentile_results = {p: np.percentile(query_times, p) for p in percentiles}
  
      logging.info("Query Time Percentiles (milliseconds):")
      for percentile, value in percentile_results.items():
          logging.info(f"{percentile}th percentile: {value:.3f} ms")
  
      db.drop_table("vectors")
  
  
  if __name__ == "__main__":
      main()
  
apis: lancedb.connect
extract_api: [((117, 213), 'logging.basicConfig', 'logging.basicConfig', ([], {'level': 'logging.INFO', 'format': '"""%(asctime)s - %(levelname)s - %(message)s"""'}), "(level=logging.INFO, format=\n    '%(asctime)s - %(levelname)s - %(message)s')\n", (136, 213), False, 'import logging\n'), ((922, 964), 'numpy.random.random', 'np.random.random', (['(num_vectors, dimension)'], {}), '((num_vectors, dimension))\n', (938, 964), True, 'import numpy as np\n'), ((1097, 1128), 'lancedb.connect', 'lancedb.connect', (['"""./vectors.db"""'], {}), "('./vectors.db')\n", (1112, 1128), False, 'import lancedb\n'), ((1134, 1174), 'logging.info', 'logging.info', (['"""Starting Generating Data"""'], {}), "('Starting Generating Data')\n", (1146, 1174), False, 'import logging\n'), ((1323, 1363), 'logging.info', 'logging.info', (['"""Finished Generating Data"""'], {}), "('Finished Generating Data')\n", (1335, 1363), False, 'import logging\n'), ((1369, 1408), 'logging.info', 'logging.info', (['"""Starting to insert data"""'], {}), "('Starting to insert data')\n", (1381, 1408), False, 'import logging\n'), ((1723, 1762), 'logging.info', 'logging.info', (['"""Finished inserting data"""'], {}), "('Finished inserting data')\n", (1735, 1762), False, 'import logging\n'), ((1768, 1800), 'logging.info', 'logging.info', (['"""Starting Queries"""'], {}), "('Starting Queries')\n", (1780, 1800), False, 'import logging\n'), ((2334, 2388), 'logging.info', 'logging.info', (['"""Query Time Percentiles (milliseconds):"""'], {}), "('Query Time Percentiles (milliseconds):')\n", (2346, 2388), False, 'import logging\n'), ((1500, 1556), 'logging.info', 'logging.info', (['f"""Starting to insert data with offset {i}"""'], {}), "(f'Starting to insert data with offset {i}')\n", (1512, 1556), False, 'import logging\n'), ((1661, 1717), 'logging.info', 'logging.info', (['f"""Finished inserting data with offset {i}"""'], {}), "(f'Finished inserting data with offset {i}')\n", (1673, 1717), False, 'import logging\n'), ((1896, 1907), 'time.time', 'time.time', ([], {}), '()\n', (1905, 1907), False, 'import time\n'), ((2015, 2026), 'time.time', 'time.time', ([], {}), '()\n', (2024, 2026), False, 'import time\n'), ((2277, 2306), 'numpy.percentile', 'np.percentile', (['query_times', 'p'], {}), '(query_times, p)\n', (2290, 2306), True, 'import numpy as np\n'), ((2454, 2512), 'logging.info', 'logging.info', (['f"""{percentile}th percentile: {value:.3f} ms"""'], {}), "(f'{percentile}th percentile: {value:.3f} ms')\n", (2466, 2512), False, 'import logging\n'), ((2177, 2211), 'logging.info', 'logging.info', (['f"""Iteration {i + 1}"""'], {}), "(f'Iteration {i + 1}')\n", (2189, 2211), False, 'import logging\n'), ((558, 585), 'numpy.random.random', 'np.random.random', (['dimension'], {}), '(dimension)\n', (574, 585), True, 'import numpy as np\n')]