code: 
  
  from langchain.chat_models import ChatOpenAI
  from langchain.prompts import ChatPromptTemplate
  from langchain_core.output_parsers import StrOutputParser
  from langchain_core.runnables import RunnablePassthrough
  
  from langchain_community.vectorstores import LanceDB
  from langchain.embeddings.openai import OpenAIEmbeddings
  import lancedb
  import pyarrow as pa
  
  from langchain.document_loaders import TextLoader
  
  def load_character_sheet(path):
      loader = TextLoader(path)
      return loader.load()
  
  
  def connect():
      embedding_function = OpenAIEmbeddings()
  
      db = lancedb.connect('db')
      table = db.open_table('character_sheets')
      return LanceDB(table, embedding_function)
  
  
  def generate_character_embeddings(path):
      embeddings = OpenAIEmbeddings()
      
      db = lancedb.connect("db")
      character_sheet = load_character_sheet(path)
      table = db.create_table(
          "character_sheets",
           data=[
              {
                  "vector": embeddings.embed_query("Hello World"),
                  "text": "Hello World",
                  "id": "1",
              }
          ],
          mode="overwrite",
      )
  
      # Load the document, split it into chunks, embed each chunk and load it into the vector store.
      db = LanceDB.from_documents(character_sheet, embeddings, connection=table)
      query = "What is Nebula's equipment?"
      docs = db.similarity_search(query)
      print(docs)
  
  
  def retriever():
      # Create a retriever that fetches documents from multiple tables
      lance_retriever = connect().as_retriever(search_kwargs={'k': 1})
      template = """Answer the question based only on the following context:
      {context}.
  
      Question: {question}
      """
  
      prompt = ChatPromptTemplate.from_template(template)
      model = ChatOpenAI()
  
      return (
          {"context": lance_retriever, "question": RunnablePassthrough()}
          | prompt
          | model
          | StrOutputParser()
      )
  
  
  def retriever_tool(question):
      response = retriever().invoke(question)
      return response
      
  
  # Create a retriever that fetches documents from multiple tables
  if __name__ == "__main__":
      print(retriever().invoke("What is Mendiete Skiari's traits, bonds and flaws?"))
      # for testing the db directly
      # db = connect()
      # query = "Who is Captain Cura's class?"
      # docs = db.similarity_search(query)
      # print(docs)
apis: lancedb.connect
extract_api: [((455, 471), 'langchain.document_loaders.TextLoader', 'TextLoader', (['path'], {}), '(path)\n', (465, 471), False, 'from langchain.document_loaders import TextLoader\n'), ((539, 557), 'langchain.embeddings.openai.OpenAIEmbeddings', 'OpenAIEmbeddings', ([], {}), '()\n', (555, 557), False, 'from langchain.embeddings.openai import OpenAIEmbeddings\n'), ((568, 589), 'lancedb.connect', 'lancedb.connect', (['"""db"""'], {}), "('db')\n", (583, 589), False, 'import lancedb\n'), ((647, 681), 'langchain_community.vectorstores.LanceDB', 'LanceDB', (['table', 'embedding_function'], {}), '(table, embedding_function)\n', (654, 681), False, 'from langchain_community.vectorstores import LanceDB\n'), ((742, 760), 'langchain.embeddings.openai.OpenAIEmbeddings', 'OpenAIEmbeddings', ([], {}), '()\n', (758, 760), False, 'from langchain.embeddings.openai import OpenAIEmbeddings\n'), ((775, 796), 'lancedb.connect', 'lancedb.connect', (['"""db"""'], {}), "('db')\n", (790, 796), False, 'import lancedb\n'), ((1230, 1299), 'langchain_community.vectorstores.LanceDB.from_documents', 'LanceDB.from_documents', (['character_sheet', 'embeddings'], {'connection': 'table'}), '(character_sheet, embeddings, connection=table)\n', (1252, 1299), False, 'from langchain_community.vectorstores import LanceDB\n'), ((1692, 1734), 'langchain.prompts.ChatPromptTemplate.from_template', 'ChatPromptTemplate.from_template', (['template'], {}), '(template)\n', (1724, 1734), False, 'from langchain.prompts import ChatPromptTemplate\n'), ((1747, 1759), 'langchain.chat_models.ChatOpenAI', 'ChatOpenAI', ([], {}), '()\n', (1757, 1759), False, 'from langchain.chat_models import ChatOpenAI\n'), ((1889, 1906), 'langchain_core.output_parsers.StrOutputParser', 'StrOutputParser', ([], {}), '()\n', (1904, 1906), False, 'from langchain_core.output_parsers import StrOutputParser\n'), ((1823, 1844), 'langchain_core.runnables.RunnablePassthrough', 'RunnablePassthrough', ([], {}), '()\n', (1842, 1844), False, 'from langchain_core.runnables import RunnablePassthrough\n')]