code: import os  # noqa: D100
  import sys
  
  import lancedb
  import pyarrow as pa
  from dotenv import load_dotenv
  from langchain.text_splitter import CharacterTextSplitter
  from langchain_community.document_loaders import UnstructuredMarkdownLoader
  from langchain_community.vectorstores.lancedb import LanceDB
  from langchain_openai.embeddings import OpenAIEmbeddings
  
  load_dotenv()
  
  
  def initialize_vectorstore() -> LanceDB:  # noqa: D103
      db = lancedb.connect(os.environ["LANCEDB_DB"])
      try:
          table = db.open_table(os.environ["LANCEDB_TABLE"])
      except FileNotFoundError:
          schema = pa.schema(
              [
                  pa.field("vector", pa.list_(pa.float32(), list_size=1536)),
                  pa.field("id", pa.string()),
                  pa.field("text", pa.string()),
                  pa.field("source", pa.string()),
              ],
          )
          table = db.create_table(
              os.environ["LANCEDB_TABLE"],
              schema=schema,
          )
  
      embeddings = OpenAIEmbeddings()
  
      return LanceDB(
          table,
          embeddings,
      )
  
  
  if __name__ == "__main__":
      file_path = sys.argv[1]
      loader = UnstructuredMarkdownLoader(file_path)
      raw_docs = loader.load()
  
      text_splitter = CharacterTextSplitter(
          chunk_size=300,
          chunk_overlap=30,
      )
      docs = text_splitter.split_documents(raw_docs)
  
      vectorstore = initialize_vectorstore()
      vectorstore.add_documents(docs)
  
apis: lancedb.connect
extract_api: [((356, 369), 'dotenv.load_dotenv', 'load_dotenv', ([], {}), '()\n', (367, 369), False, 'from dotenv import load_dotenv\n'), ((436, 477), 'lancedb.connect', 'lancedb.connect', (["os.environ['LANCEDB_DB']"], {}), "(os.environ['LANCEDB_DB'])\n", (451, 477), False, 'import lancedb\n'), ((989, 1007), 'langchain_openai.embeddings.OpenAIEmbeddings', 'OpenAIEmbeddings', ([], {}), '()\n', (1005, 1007), False, 'from langchain_openai.embeddings import OpenAIEmbeddings\n'), ((1020, 1046), 'langchain_community.vectorstores.lancedb.LanceDB', 'LanceDB', (['table', 'embeddings'], {}), '(table, embeddings)\n', (1027, 1046), False, 'from langchain_community.vectorstores.lancedb import LanceDB\n'), ((1140, 1177), 'langchain_community.document_loaders.UnstructuredMarkdownLoader', 'UnstructuredMarkdownLoader', (['file_path'], {}), '(file_path)\n', (1166, 1177), False, 'from langchain_community.document_loaders import UnstructuredMarkdownLoader\n'), ((1228, 1283), 'langchain.text_splitter.CharacterTextSplitter', 'CharacterTextSplitter', ([], {'chunk_size': '(300)', 'chunk_overlap': '(30)'}), '(chunk_size=300, chunk_overlap=30)\n', (1249, 1283), False, 'from langchain.text_splitter import CharacterTextSplitter\n'), ((725, 736), 'pyarrow.string', 'pa.string', ([], {}), '()\n', (734, 736), True, 'import pyarrow as pa\n'), ((772, 783), 'pyarrow.string', 'pa.string', ([], {}), '()\n', (781, 783), True, 'import pyarrow as pa\n'), ((821, 832), 'pyarrow.string', 'pa.string', ([], {}), '()\n', (830, 832), True, 'import pyarrow as pa\n'), ((662, 674), 'pyarrow.float32', 'pa.float32', ([], {}), '()\n', (672, 674), True, 'import pyarrow as pa\n')]