code: # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
  # SPDX-License-Identifier: MIT-0
  
  import os
  
  from langchain.text_splitter import CharacterTextSplitter
  from langchain.vectorstores import LanceDB
  from langchain.embeddings import BedrockEmbeddings
  from langchain.document_loaders import PyPDFDirectoryLoader
  
  import lancedb as ldb
  import pyarrow as pa
  
  embeddings = BedrockEmbeddings()
  
  # we split the data into chunks of 1,000 characters, with an overlap
  # of 200 characters between the chunks, which helps to give better results
  # and contain the context of the information between chunks
  text_splitter = CharacterTextSplitter(chunk_size=1000, chunk_overlap=200)
  
  db = ldb.connect('/tmp/embeddings')
  
  schema = pa.schema(
    [
        pa.field("vector", pa.list_(pa.float32(), 1536)), # document vector with 1.5k dimensions (TitanEmbedding)
        pa.field("text", pa.string()), # langchain requires it
        pa.field("id", pa.string()) # langchain requires it
    ])
  
  tbl = db.create_table("doc_table", schema=schema)
  
  # load the document as before
  
  loader = PyPDFDirectoryLoader("./docs/")
  
  docs = loader.load()
  docs = text_splitter.split_documents(docs)
  
  LanceDB.from_documents(docs, embeddings, connection=tbl)
  
apis: lancedb.connect
extract_api: [((384, 403), 'langchain.embeddings.BedrockEmbeddings', 'BedrockEmbeddings', ([], {}), '()\n', (401, 403), False, 'from langchain.embeddings import BedrockEmbeddings\n'), ((625, 682), 'langchain.text_splitter.CharacterTextSplitter', 'CharacterTextSplitter', ([], {'chunk_size': '(1000)', 'chunk_overlap': '(200)'}), '(chunk_size=1000, chunk_overlap=200)\n', (646, 682), False, 'from langchain.text_splitter import CharacterTextSplitter\n'), ((689, 719), 'lancedb.connect', 'ldb.connect', (['"""/tmp/embeddings"""'], {}), "('/tmp/embeddings')\n", (700, 719), True, 'import lancedb as ldb\n'), ((1073, 1104), 'langchain.document_loaders.PyPDFDirectoryLoader', 'PyPDFDirectoryLoader', (['"""./docs/"""'], {}), "('./docs/')\n", (1093, 1104), False, 'from langchain.document_loaders import PyPDFDirectoryLoader\n'), ((1171, 1227), 'langchain.vectorstores.LanceDB.from_documents', 'LanceDB.from_documents', (['docs', 'embeddings'], {'connection': 'tbl'}), '(docs, embeddings, connection=tbl)\n', (1193, 1227), False, 'from langchain.vectorstores import LanceDB\n'), ((880, 891), 'pyarrow.string', 'pa.string', ([], {}), '()\n', (889, 891), True, 'import pyarrow as pa\n'), ((939, 950), 'pyarrow.string', 'pa.string', ([], {}), '()\n', (948, 950), True, 'import pyarrow as pa\n'), ((779, 791), 'pyarrow.float32', 'pa.float32', ([], {}), '()\n', (789, 791), True, 'import pyarrow as pa\n')]