code: import typer
  import openai
  from rag_app.models import TextChunk
  from lancedb import connect
  from typing import List
  from pathlib import Path
  from rich.console import Console
  from rich.table import Table
  from rich import box
  import duckdb
  
  app = typer.Typer()
  
  
  @app.command(help="Query LanceDB for some results")
  def db(
      db_path: str = typer.Option(help="Your LanceDB path"),
      table_name: str = typer.Option(help="Table to ingest data into"),
      query: str = typer.Option(help="Text to query against existing vector db chunks"),
      n: int = typer.Option(default=3, help="Maximum number of chunks to return"),
  ):
      if not Path(db_path).exists():
          raise ValueError(f"Database path {db_path} does not exist.")
      db = connect(db_path)
      db_table = db.open_table(table_name)
  
      client = openai.OpenAI()
      query_vector = (
          client.embeddings.create(
              input=query, model="text-embedding-3-large", dimensions=256
          )
          .data[0]
          .embedding
      )
  
      results: List[TextChunk] = (
          db_table.search(query_vector).limit(n).to_pydantic(TextChunk)
      )
  
      sql_table = db_table.to_lance()
      df = duckdb.query(
          "SELECT doc_id, count(chunk_id) as count FROM sql_table GROUP BY doc_id"
      ).to_df()
  
      doc_ids = df["doc_id"].to_list()
      counts = df["count"].to_list()
  
      doc_id_to_count = {id: chunk_count for id, chunk_count in zip(doc_ids, counts)}
  
      table = Table(title="Results", box=box.HEAVY, padding=(1, 2), show_lines=True)
      table.add_column("Post Title", style="green", max_width=30)
      table.add_column("Content", style="magenta", max_width=120)
      table.add_column("Chunk Number", style="yellow")
      table.add_column("Publish Date", style="blue")
  
      for result in results:
          chunk_number = f"{result.chunk_id}"
          table.add_row(
              f"{result.post_title}({result.source})",
              result.text,
              f"{chunk_number}/{doc_id_to_count[result.doc_id]}",
              result.publish_date.strftime("%Y-%m"),
          )
      Console().print(table)
  
apis: lancedb.connect
extract_api: [((245, 258), 'typer.Typer', 'typer.Typer', ([], {}), '()\n', (256, 258), False, 'import typer\n'), ((340, 378), 'typer.Option', 'typer.Option', ([], {'help': '"""Your LanceDB path"""'}), "(help='Your LanceDB path')\n", (352, 378), False, 'import typer\n'), ((402, 448), 'typer.Option', 'typer.Option', ([], {'help': '"""Table to ingest data into"""'}), "(help='Table to ingest data into')\n", (414, 448), False, 'import typer\n'), ((467, 535), 'typer.Option', 'typer.Option', ([], {'help': '"""Text to query against existing vector db chunks"""'}), "(help='Text to query against existing vector db chunks')\n", (479, 535), False, 'import typer\n'), ((550, 616), 'typer.Option', 'typer.Option', ([], {'default': '(3)', 'help': '"""Maximum number of chunks to return"""'}), "(default=3, help='Maximum number of chunks to return')\n", (562, 616), False, 'import typer\n'), ((734, 750), 'lancedb.connect', 'connect', (['db_path'], {}), '(db_path)\n', (741, 750), False, 'from lancedb import connect\n'), ((806, 821), 'openai.OpenAI', 'openai.OpenAI', ([], {}), '()\n', (819, 821), False, 'import openai\n'), ((1437, 1507), 'rich.table.Table', 'Table', ([], {'title': '"""Results"""', 'box': 'box.HEAVY', 'padding': '(1, 2)', 'show_lines': '(True)'}), "(title='Results', box=box.HEAVY, padding=(1, 2), show_lines=True)\n", (1442, 1507), False, 'from rich.table import Table\n'), ((1157, 1248), 'duckdb.query', 'duckdb.query', (['"""SELECT doc_id, count(chunk_id) as count FROM sql_table GROUP BY doc_id"""'], {}), "(\n    'SELECT doc_id, count(chunk_id) as count FROM sql_table GROUP BY doc_id')\n", (1169, 1248), False, 'import duckdb\n'), ((2042, 2051), 'rich.console.Console', 'Console', ([], {}), '()\n', (2049, 2051), False, 'from rich.console import Console\n'), ((632, 645), 'pathlib.Path', 'Path', (['db_path'], {}), '(db_path)\n', (636, 645), False, 'from pathlib import Path\n')]