code: from llama_index.retrievers import BaseRetriever
  from llama_index import QueryBundle
  from llama_index.schema import NodeWithScore
  from llama_index.vector_stores import VectorStoreQuery
  from typing import List, Sequence, Any
  from llama_index.tools import BaseTool, adapt_to_async_tool
  from llama_index import Document, VectorStoreIndex
  
  
  class ToolRetriever(BaseRetriever):
      def __init__(
          self,
          tools: Sequence[BaseTool],
          sql_tools: Sequence[BaseTool],
          embed_model: Any,
          index: VectorStoreIndex = None,
          message: str = "",
          append_sql: bool = True,
          similarity_top_k: int = 8,
          logger=None,
      ) -> None:
          self._message = message
          self._tools = tools
          self._index = index
          self._sql_tools = sql_tools
          self._append_sql = append_sql
          self._similarity_top_k = similarity_top_k
          self._embed_model = embed_model
          self._logger = logger
  
      def _retrieve(self, query_bundle: QueryBundle) -> List[NodeWithScore]:
          """Retrieve."""
          from llama_index.retrievers import VectorIndexRetriever
  
          retriever = VectorIndexRetriever(
              index=self._index,
              similarity_top_k=self._similarity_top_k,
          )
  
          response = retriever.retrieve(query_bundle)
  
          tools_ = []
  
          for n in response:
              tools_.append(self._tools[n.metadata["idx"]])
  
          if self._append_sql:
              tools_.append(self._sql_tools)
          #        tools_.append(self._tools[-1])  # add SQL tool
  
          self._logger.debug(f"Tools before: {self._tools}")
          _tmp = set(adapt_to_async_tool(t) for t in tools_)
          self._logger.debug(f"Tools after: {list(_tmp)}")
          return list(_tmp)
  
          # return [adapt_to_async_tool(t) for t in tools_]
  
      def create_vector_index_from_tools(self):
          from llama_index.tools import adapt_to_async_tool
  
          get_tools = lambda _: self._tools
          tools = [adapt_to_async_tool(t) for t in get_tools("")]
          docs = [
              str(
                  "idx: "
                  + str(idx)
                  + ", name: "
                  + str(t.metadata.name)
                  + ", description: "
                  + str(t.metadata.description)
              )
              for idx, t in enumerate(tools)
          ]
  
          documents = [
              Document(text=t, metadata={"idx": idx}) for idx, t in enumerate(docs)
          ]
  
          self._index = VectorStoreIndex.from_documents(
              documents, embed_model=self._embed_model
          )
  
apis: llama_index.VectorStoreIndex.from_documents llama_index.tools.adapt_to_async_tool llama_index.retrievers.VectorIndexRetriever llama_index.Document
extract_api: [((1143, 1228), 'llama_index.retrievers.VectorIndexRetriever', 'VectorIndexRetriever', ([], {'index': 'self._index', 'similarity_top_k': 'self._similarity_top_k'}), '(index=self._index, similarity_top_k=self._similarity_top_k\n    )\n', (1163, 1228), False, 'from llama_index.retrievers import VectorIndexRetriever\n'), ((2469, 2542), 'llama_index.VectorStoreIndex.from_documents', 'VectorStoreIndex.from_documents', (['documents'], {'embed_model': 'self._embed_model'}), '(documents, embed_model=self._embed_model)\n', (2500, 2542), False, 'from llama_index import Document, VectorStoreIndex\n'), ((1982, 2004), 'llama_index.tools.adapt_to_async_tool', 'adapt_to_async_tool', (['t'], {}), '(t)\n', (2001, 2004), False, 'from llama_index.tools import adapt_to_async_tool\n'), ((2366, 2405), 'llama_index.Document', 'Document', ([], {'text': 't', 'metadata': "{'idx': idx}"}), "(text=t, metadata={'idx': idx})\n", (2374, 2405), False, 'from llama_index import Document, VectorStoreIndex\n'), ((1635, 1657), 'llama_index.tools.adapt_to_async_tool', 'adapt_to_async_tool', (['t'], {}), '(t)\n', (1654, 1657), False, 'from llama_index.tools import adapt_to_async_tool\n')]