> ## Documentation Index
> Fetch the complete documentation index at: https://liquidai-example-leonie-demo.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# LFM2-1.2B-RAG

> 1.2B parameter RAG model (deprecated - use LFM2.5-1.2B-Instruct with retrieval models instead)

<a href="/lfm/models/liquid-nanos" className="back-button">← Back to Liquid Nanos</a>

<Warning>
  This model is deprecated. For generation, use [LFM2.5-1.2B-Instruct](/lfm/models/lfm25-1.2b-instruct). For retrieval, pair it with [LFM2.5-Embedding-350M](/lfm/models/lfm25-embedding-350m) or [LFM2.5-ColBERT-350M](/lfm/models/lfm25-colbert-350m) as part of your RAG pipeline.
</Warning>

LFM2-1.2B-RAG is optimized for answering questions grounded in provided context documents. It excels at extracting relevant information from retrieved documents while avoiding hallucination.

<div style={{display: 'flex', gap: '0.5rem', margin: '0.5rem 0 1.5rem 0'}}>
  <a href="https://huggingface.co/LiquidAI/LFM2-1.2B-RAG" style={{padding: '0.35rem 0.7rem', borderRadius: '4px', fontSize: '0.85rem', fontWeight: 600, textDecoration: 'none', backgroundColor: '#fbbf24'}}><span style={{color: '#000'}}>HF</span></a>
  <a href="https://huggingface.co/LiquidAI/LFM2-1.2B-RAG-GGUF" style={{padding: '0.35rem 0.7rem', borderRadius: '4px', fontSize: '0.85rem', fontWeight: 600, textDecoration: 'none', backgroundColor: '#60a5fa'}}><span style={{color: '#000'}}>GGUF</span></a>
  <a href="https://huggingface.co/onnx-community/LFM2-1.2B-RAG-ONNX" style={{padding: '0.35rem 0.7rem', borderRadius: '4px', fontSize: '0.85rem', fontWeight: 600, textDecoration: 'none', backgroundColor: '#86efac'}}><span style={{color: '#000'}}>ONNX</span></a>
</div>

## Specifications

| Property                | Value                          |
| ----------------------- | ------------------------------ |
| Parameters              | 1.2B                           |
| Context Length          | 32K tokens                     |
| Task                    | Retrieval-Augmented Generation |
| Recommended Temperature | 0                              |

<div className="use-cases">
  <CardGroup cols={3}>
    <Card title="Document Q&A" icon="file-magnifying-glass">
      Answer from retrieved docs
    </Card>

    <Card title="Knowledge Base" icon="database">
      Query internal knowledge
    </Card>

    <Card title="Grounded Answers" icon="anchor">
      Reduce hallucination
    </Card>
  </CardGroup>
</div>

## Prompting Recipe

<Warning>
  Use `temperature=0` (greedy decoding) for best results. Provide relevant documents in the system prompt.
</Warning>

**System Prompt Format:**

```
The following documents may provide you additional information to answer questions:

<document1>
[Document content here]
</document1>

<document2>
[Document content here]
</document2>
```

## Quick Start

<Tabs>
  <Tab title="Transformers">
    **Install:**

    ```bash theme={null}
    pip install "transformers>=5.2.0" torch accelerate
    ```

    **Run:**

    ```python theme={null}
    from transformers import AutoTokenizer, AutoModelForCausalLM

    model_id = "LiquidAI/LFM2-1.2B-RAG"
    tokenizer = AutoTokenizer.from_pretrained(model_id)
    model = AutoModelForCausalLM.from_pretrained(model_id, device_map="auto")

    system_prompt = """The following documents may provide you additional information to answer questions:

    <document1>
    The centre, which was created in 1906, has been instrumental in advancing
    agriculture research. The library at the Agriculture Canada research centre
    in Lethbridge serves 48 scientists and 85 technicians, along with many
    visiting staff and students.
    </document1>
    """

    user_input = "How many individuals were reported to be served by the library at the Agriculture Canada research centre in Lethbridge?"

    messages = [
        {"role": "system", "content": system_prompt},
        {"role": "user", "content": user_input}
    ]

    inputs = tokenizer.apply_chat_template(messages, return_tensors="pt", return_dict=True).to(model.device)
    outputs = model.generate(**inputs, max_new_tokens=256, temperature=0, do_sample=False)
    response = tokenizer.decode(outputs[0], skip_special_tokens=True)
    print(response)
    # Output: The library serves 48 scientists and 85 technicians, along with many visiting staff and students.
    ```
  </Tab>

  <Tab title="llama.cpp">
    **Download GGUF:**

    ```bash theme={null}
    hf download LiquidAI/LFM2-1.2B-RAG-GGUF \
      --local-dir ./LFM2-1.2B-RAG-GGUF
    ```

    **Run:**

    ```bash theme={null}
    llama-cli -m ./LFM2-1.2B-RAG-GGUF/LFM2-1.2B-RAG-Q4_K_M.gguf \
      -sys "The following documents may provide information: <doc1>The capital of France is Paris.</doc1>" \
      -p "What is the capital of France?" \
      --temp 0
    ```
  </Tab>
</Tabs>
