Elffuss BraidHub

kikocis/lancedb public

main 路 1.6 KiBRenderedRawPermalink
1**FLARE 馃挜**
2====================================================================
3FLARE, 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 ![flare](https://raw.githubusercontent.com/lancedb/assets/main/docs/assets/rag/flare.gif)
9 <figcaption>FLARE: <a href="https://github.com/jzbjyb/FLARE">Source</a></figcaption>
10</figure>
11
12[![Open In Colab](../../assets/colab.svg)](https://colab.research.google.com/github/lancedb/vectordb-recipes/blob/main/examples/better-rag-FLAIR/main.ipynb)
13
14Here鈥檚 a code snippet for using FLARE with Langchain
15
16```python
17from langchain.vectorstores import LanceDB
18from langchain.document_loaders import ArxivLoader
19from langchain.chains import FlareChain
20from langchain.prompts import PromptTemplate
21from langchain.chains import LLMChain
22from langchain.llms import OpenAI
23
24llm = OpenAI()
25
26# load dataset
27
28# LanceDB retriever
29vector_store = LanceDB.from_documents(doc_chunks, embeddings, connection=table)
30retriever = vector_store.as_retriever()
31
32# define flare chain
33flare = FlareChain.from_llm(llm=llm,retriever=vector_store_retriever,max_generation_len=300,min_prob=0.45)
34
35result = flare.run(input_text)
36```
37
38[![Open In Colab](../../assets/colab.svg)](https://colab.research.google.com/github/lancedb/vectordb-recipes/blob/main/examples/better-rag-FLAIR/main.ipynb)