| 1 | **FLARE 馃挜** |
| 2 | ==================================================================== |
| 3 | FLARE, stands for Forward-Looking Active REtrieval augmented generation is a generic retrieval-augmented generation method that actively decides when and what to retrieve using a prediction of the upcoming sentence to anticipate future content and utilize it as the query to retrieve relevant documents if it contains low-confidence tokens. |
| 4 | |
| 5 | **[Official Paper](https://arxiv.org/abs/2305.06983)** |
| 6 | |
| 7 | <figure markdown="span"> |
| 8 |  |
| 9 | <figcaption>FLARE: <a href="https://github.com/jzbjyb/FLARE">Source</a></figcaption> |
| 10 | </figure> |
| 11 | |
| 12 | [](https://colab.research.google.com/github/lancedb/vectordb-recipes/blob/main/examples/better-rag-FLAIR/main.ipynb) |
| 13 | |
| 14 | Here鈥檚 a code snippet for using FLARE with Langchain |
| 15 | |
| 16 | ```python |
| 17 | from langchain.vectorstores import LanceDB |
| 18 | from langchain.document_loaders import ArxivLoader |
| 19 | from langchain.chains import FlareChain |
| 20 | from langchain.prompts import PromptTemplate |
| 21 | from langchain.chains import LLMChain |
| 22 | from langchain.llms import OpenAI |
| 23 | |
| 24 | llm = OpenAI() |
| 25 | |
| 26 | # load dataset |
| 27 | |
| 28 | # LanceDB retriever |
| 29 | vector_store = LanceDB.from_documents(doc_chunks, embeddings, connection=table) |
| 30 | retriever = vector_store.as_retriever() |
| 31 | |
| 32 | # define flare chain |
| 33 | flare = FlareChain.from_llm(llm=llm,retriever=vector_store_retriever,max_generation_len=300,min_prob=0.45) |
| 34 | |
| 35 | result = flare.run(input_text) |
| 36 | ``` |
| 37 | |
| 38 | [](https://colab.research.google.com/github/lancedb/vectordb-recipes/blob/main/examples/better-rag-FLAIR/main.ipynb) |