def extract_features_and_store_in_faiss(model, batch_size=32, train_batch_size=10000):
    """Extracts features from tiles using a deep learning model and stores them in a FAISS index."""
    d = 1024  # Dimension of the feature vectors
    nlist = 10000 #100  # Number of clusters
    m = 64  # Number of subquantizers
    k = 16   # Bits per subquantizer
    # Step 1: Create a quantizer for clustering
    quantizer = faiss.IndexFlatL2(d)
    # Step 2: Create the IndexIVFPQ object
    index = faiss.IndexIVFPQ(quantizer, d, nlist, m, k)
    index.nprobe = 256
    # Step 3: Train the index (we'll need some data to do this)
    file_names = []
    conn = sqlite3.connect(mbtiles_path)
    cursor = conn.cursor()
    query = f"""
        SELECT zoom_level, tile_column, tile_row
        FROM tiles
        """
    cursor.execute(query)
    tiles = cursor.fetchall()
    conn.close()
    
    conn = sqlite3.connect(mbtiles_path) 
    cursor = conn.cursor() 
    model = load_model()
    transform = transforms.Compose([transforms.Resize((224, 224)),
                                    transforms.ToTensor(),
                                    transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])])
    device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
    start_time = time.time()  # Record the start time
    train_features = []
    total_images = 0
    batch_tiles = []
    batch_file_names = []
    for idx in range(0, len(tiles)):
        zoom, x, y = tiles[idx]
        stitch_image = stitch_tiles(cursor,zoom, x, y,-1, -1, 1, 1)
        tile_image = np.array(stitch_image)[128:640, 128:640, :]
        image = transform(Image.fromarray(tile_image)).unsqueeze(0)
        batch_tiles.append(image)
        batch_file_names.append(f'{x}_{y}_{zoom}')
        if len(batch_tiles) == batch_size:
            images_tensor = torch.cat(batch_tiles, dim=0).to(device)
            with torch.no_grad():
                global_features = model(images_tensor)
            features = global_features.cpu().numpy().astype('float32')
            train_features.append(features)
            file_names.extend(batch_file_names)
            total_images += len(batch_tiles)
            end_time = time.time() 
            print(f"Processed {total_images} images. Elapsed time: {end_time - start_time} seconds")
            start_time = time.time()
            batch_tiles = []
            batch_file_names = []
            feature_count = len(train_features)*batch_size
            if feature_count > train_batch_size:
                train_features_np = np.vstack(train_features)
                index.train(train_features_np)
                index.add(train_features_np)
                train_features = []  # 清空已添加的特征

    # Process remaining tiles
    if batch_tiles:
        images_tensor = torch.cat(batch_tiles, dim=0).to(device)
        with torch.no_grad():
            global_features = model(images_tensor)
        features = global_features.cpu().numpy().astype('float32')
        train_features.append(features)
        file_names.extend(batch_file_names)
        total_images += len(batch_tiles)
        
    if train_features:
        train_features = np.vstack(train_features)
        index.train(train_features)
        index.add(train_features)
        end_time = time.time()
        print(f"Processed {total_images} images. Elapsed time: {end_time - start_time} seconds")
    
    return index, file_names，以上faiss提取特征生成index数据有问题么，有6000万条数据，faiss的参数设置合理么，train_batch_size=10000的时候会不会有内存问题（电脑内存是64G）