INF-Retriever-v1-1.5B is a lightweight version of the INF-Retriever-v1, an LLM-based dense retrieval model developed by INF TECH.
It is built upon the gte-Qwen2-1.5B-instruct model and specifically fine-tuned to excel in retrieval tasks, particularly for Chinese and English data.
As of February 19, 2025, INF-Retriever-v1-1.5B ranks both No.1 on the Automated Heterogeneous Information Retrieval Benchmark of version 24.04 & 24.05(AIR-Bench) for the bilingual Chinese and English sub-leaderboard, among models with fewer than 7B parameters. This demonstrates its cutting-edge performance in heterogeneous information retrieval tasks.
Key Features
Optimized for Chinese and English retrieval: The model has been specifically fine-tuned with retrieval-focused datasets in both languages, significantly improving its accuracy and efficiency for a variety of retrieval scenarios.
Top-tier performance: INF-Retriever-v1-1.5B has achieved outstanding results on the AIR-Bench leaderboard, making it a top choice for heterogeneous information retrieval tasks across various domains.
Model Details
Model Size: 1.5B
Embedding Dimension: 1536
Max Input Tokens: 32768
Language Support: Chinese & English (also effective in other languages)
Usage
Sentence Transformers
python
1from sentence_transformers import SentenceTransformer
23model = SentenceTransformer("infly/inf-retriever-v1-1.5b", trust_remote_code=True)4# In case you want to reduce the maximum length:5model.max_seq_length =819267queries =[8"how much protein should a female eat",9"summit define",10]11documents =[12"As a general guideline, the CDC's average requirement of protein for women ages 19 to 70 is 46 grams per day. But, as you can see from this chart, you'll need to increase that if you're expecting or training for a marathon. Check out the chart below to see how much protein you should be eating each day.",13"Definition of summit for English Language Learners. : 1 the highest point of a mountain : the top of a mountain. : 2 the highest level. : 3 a meeting or series of meetings between the leaders of two or more governments.",14]1516query_embeddings = model.encode(queries, prompt_name="query")17document_embeddings = model.encode(documents)1819scores =(query_embeddings @ document_embeddings.T)*10020print(scores.tolist())21# [[89.36092376708984, 69.16694641113281], [57.51953125, 79.65923309326172]]
Transformers
python
1import torch
2import torch.nn.functional as F
34from torch import Tensor
5from transformers import AutoTokenizer, AutoModel
678deflast_token_pool(last_hidden_states: Tensor,9 attention_mask: Tensor)-> Tensor:10 left_padding =(attention_mask[:,-1].sum()== attention_mask.shape[0])11if left_padding:12return last_hidden_states[:,-1]13else:14 sequence_lengths = attention_mask.sum(dim=1)-115 batch_size = last_hidden_states.shape[0]16return last_hidden_states[torch.arange(batch_size, device=last_hidden_states.device), sequence_lengths]171819defget_detailed_instruct(task_description:str, query:str)->str:20returnf'Instruct: {task_description}\nQuery: {query}'212223# Each query must come with a one-sentence instruction that describes the task24task ='Given a web search query, retrieve relevant passages that answer the query'25queries =[26 get_detailed_instruct(task,'how much protein should a female eat'),27 get_detailed_instruct(task,'summit define')28]29# No need to add instruction for retrieval documents30documents =[31"As a general guideline, the CDC's average requirement of protein for women ages 19 to 70 is 46 grams per day. But, as you can see from this chart, you'll need to increase that if you're expecting or training for a marathon. Check out the chart below to see how much protein you should be eating each day.",32"Definition of summit for English Language Learners. : 1 the highest point of a mountain : the top of a mountain. : 2 the highest level. : 3 a meeting or series of meetings between the leaders of two or more governments."33]34input_texts = queries + documents
3536tokenizer = AutoTokenizer.from_pretrained('infly/inf-retriever-v1-1.5b', trust_remote_code=True)37model = AutoModel.from_pretrained('infly/inf-retriever-v1-1.5b', trust_remote_code=True)3839max_length =81924041# Tokenize the input texts42batch_dict = tokenizer(input_texts, max_length=max_length, padding=True, truncation=True, return_tensors='pt')43outputs = model(**batch_dict)44embeddings = last_token_pool(outputs.last_hidden_state, batch_dict['attention_mask'])4546# normalize embeddings47embeddings = F.normalize(embeddings, p=2, dim=1)48scores =(embeddings[:2] @ embeddings[2:].T)*10049print(scores.tolist())50# [[89.36091613769531, 69.16694641113281], [57.519447326660156, 79.65917205810547]]
Evaluation
AIR-Bench
INF-Retriever-v1-1.5B has demonstrated superior retrieval capabilities across multiple domains and languages. The results from the Automated Heterogeneous Information Retrieval Benchmark (AIR-Bench) as of February 19, 2025, are as follows:
Although INF-Retriever-v1-1.5B has been fine-tuned exclusively on English and Chinese, it continues to perform exceptionally well across other languages.