code: import flask
  import lancedb
  import openai
  import langchain
  from langchain.embeddings import OpenAIEmbeddings
  from langchain.vectorstores import LanceDB
  from langchain.docstore.document import Document
  from langchain.embeddings.openai import OpenAIEmbeddings
  from langchain.text_splitter import CharacterTextSplitter
  import os
  from flask import Flask, render_template, request, jsonify
  from flask import Response
  
  from flask_cors import CORS
  
  app = Flask(__name__)
  # cors = CORS(app, resources={r"/*": {"origins": "*"}})
  
  # from dotenv import dotenv_values
  # env_vars = dotenv_values('.env')
  env_vars = {'OPENAI_API_KEY': 'sk-1234'}
  
  
  uri = "~/.lancedb"
  db = lancedb.connect(uri)
  app = Flask(__name__)
  
  OPENAI_API_KEY = env_vars['OPENAI_API_KEY']
  
  
  # Route for "/" for a web-based interface to this micro-service:
  @app.route('/')
  def index():
    return "Hello, World"
  @app.after_request
  def add_cors_headers(response):
      response.headers.add('Access-Control-Allow-Origin', '*')
      response.headers.add('Access-Control-Allow-Headers', 'Content-Type')
      response.headers.add('Access-Control-Allow-Methods', 'POST, OPTIONS')
  
      return response
  
  @app.route('/test', methods=['POST'])
  def test():
      # Process the request
      data = request.get_json()
      print(data)
      print("TESTING")
  
      # Generate the response
      response_data = {'message': 'Hello, World'}
      response = jsonify(response_data)
  
      return response
  
  # Handle OPTIONS request for CORS preflight
  @app.route('/test', methods=['OPTIONS'])
  def handle_options():
      response = jsonify({'message': 'Preflight request received'})
      response.headers.add('Access-Control-Allow-Origin', '*')
      response.headers.add('Access-Control-Allow-Headers', 'Content-Type')
      response.headers.add('Access-Control-Allow-Methods', 'POST')
      print('Testing')
      return response
  
  @app.route('/store', methods = ['POST'])
  def store_embedding():
      json_data = request.get_json()
      text = json_data['raw_text']
      metadata = json_data['metadata']
      document = Document(page_content=text, metadata=metadata)
      chunks = CharacterTextSplitter(chunk_size=1000, chunk_overlap=0).split_documents([document])
      embeddings = OpenAIEmbeddings()
  
      table = db.create_table("text", data=[
          {"vector": embeddings.embed_query("Hello World"), "text": "Hello World", "id": "1"}
      ], mode="overwrite")
  
      docsearch = LanceDB.from_documents(chunks, embeddings, connection=table)
      
      return "Loaded Document Into Table"
  
  
  @app.route('/retrieve', methods = ['POST'])
  def retrieve_embedding():
     json_data = request.get_json()
     query = json_data['query']
  
     assert len(openai.Model.list()["data"]) > 0
     
     def embed_func(query):
          rs = openai.Embedding.create(input=query, engine="text-embedding-ada-002")
          return [record["embedding"] for record in rs["data"]]
     
     query_vector = embed_func([query])[0]
     table = db.open_table("text")
     docs = table.search(query_vector).limit(10).to_df()
     print(docs)
     return docs
  
  
  
  if __name__ == '__main__':
      app.run(debug=True)
  
  
  
  
  
  
apis: lancedb.connect
extract_api: [((448, 463), 'flask.Flask', 'Flask', (['__name__'], {}), '(__name__)\n', (453, 463), False, 'from flask import Flask, render_template, request, jsonify\n'), ((658, 678), 'lancedb.connect', 'lancedb.connect', (['uri'], {}), '(uri)\n', (673, 678), False, 'import lancedb\n'), ((685, 700), 'flask.Flask', 'Flask', (['__name__'], {}), '(__name__)\n', (690, 700), False, 'from flask import Flask, render_template, request, jsonify\n'), ((1234, 1252), 'flask.request.get_json', 'request.get_json', ([], {}), '()\n', (1250, 1252), False, 'from flask import Flask, render_template, request, jsonify\n'), ((1382, 1404), 'flask.jsonify', 'jsonify', (['response_data'], {}), '(response_data)\n', (1389, 1404), False, 'from flask import Flask, render_template, request, jsonify\n'), ((1549, 1599), 'flask.jsonify', 'jsonify', (["{'message': 'Preflight request received'}"], {}), "({'message': 'Preflight request received'})\n", (1556, 1599), False, 'from flask import Flask, render_template, request, jsonify\n'), ((1921, 1939), 'flask.request.get_json', 'request.get_json', ([], {}), '()\n', (1937, 1939), False, 'from flask import Flask, render_template, request, jsonify\n'), ((2025, 2071), 'langchain.docstore.document.Document', 'Document', ([], {'page_content': 'text', 'metadata': 'metadata'}), '(page_content=text, metadata=metadata)\n', (2033, 2071), False, 'from langchain.docstore.document import Document\n'), ((2186, 2204), 'langchain.embeddings.openai.OpenAIEmbeddings', 'OpenAIEmbeddings', ([], {}), '()\n', (2202, 2204), False, 'from langchain.embeddings.openai import OpenAIEmbeddings\n'), ((2383, 2443), 'langchain.vectorstores.LanceDB.from_documents', 'LanceDB.from_documents', (['chunks', 'embeddings'], {'connection': 'table'}), '(chunks, embeddings, connection=table)\n', (2405, 2443), False, 'from langchain.vectorstores import LanceDB\n'), ((2576, 2594), 'flask.request.get_json', 'request.get_json', ([], {}), '()\n', (2592, 2594), False, 'from flask import Flask, render_template, request, jsonify\n'), ((2716, 2785), 'openai.Embedding.create', 'openai.Embedding.create', ([], {'input': 'query', 'engine': '"""text-embedding-ada-002"""'}), "(input=query, engine='text-embedding-ada-002')\n", (2739, 2785), False, 'import openai\n'), ((2085, 2140), 'langchain.text_splitter.CharacterTextSplitter', 'CharacterTextSplitter', ([], {'chunk_size': '(1000)', 'chunk_overlap': '(0)'}), '(chunk_size=1000, chunk_overlap=0)\n', (2106, 2140), False, 'from langchain.text_splitter import CharacterTextSplitter\n'), ((2640, 2659), 'openai.Model.list', 'openai.Model.list', ([], {}), '()\n', (2657, 2659), False, 'import openai\n')]