Create README.md
Browse files
README.md
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: apache-2.0
|
| 3 |
+
task_categories:
|
| 4 |
+
- text-retrieval
|
| 5 |
+
- question-answering
|
| 6 |
+
language:
|
| 7 |
+
- en
|
| 8 |
+
tags:
|
| 9 |
+
- r-language
|
| 10 |
+
- chromadb
|
| 11 |
+
- tool-retrieval
|
| 12 |
+
- data-science
|
| 13 |
+
- llm-agent
|
| 14 |
+
size_categories:
|
| 15 |
+
- n<10K
|
| 16 |
+
---
|
| 17 |
+
|
| 18 |
+
# R-Package Knowledge Base (RPKB)
|
| 19 |
+
|
| 20 |
+
This database is the official pre-computed **ChromaDB vector database** for the paper: *DARE: Aligning LLM Agents with the R Statistical Ecosystem via Distribution-Aware Retrieval*.
|
| 21 |
+
|
| 22 |
+
It contains **8,191 high-quality R functions** meticulously curated from CRAN, complete with extracted statistical metadata (Data Profiles) and pre-computed embeddings generated by the **[DARE model](https://huggingface.co/Stephen-SMJ/DARE-R-Retriever)**.
|
| 23 |
+
|
| 24 |
+
## 📊 Database Overview
|
| 25 |
+
- **Database Engine:** ChromaDB
|
| 26 |
+
- **Total Documents:** 8,191 R functions
|
| 27 |
+
- **Embedding Model:** `Stephen-SMJ/DARE-R-Retriever`
|
| 28 |
+
- **Primary Use Case:** Tool retrieval for LLM Agents executing data science and statistical workflows in R.
|
| 29 |
+
|
| 30 |
+
## 🚀 How to Use (Plug-and-Play)
|
| 31 |
+
|
| 32 |
+
You can easily download and load this database into your own Agentic workflows using the `huggingface_hub` and `chromadb` libraries.
|
| 33 |
+
|
| 34 |
+
### 1. Install Dependencies
|
| 35 |
+
```bash
|
| 36 |
+
pip install huggingface_hub chromadb sentence-transformers
|
| 37 |
+
```
|
| 38 |
+
|
| 39 |
+
### 2. Download RPKB and Connect
|
| 40 |
+
```Python
|
| 41 |
+
from huggingface_hub import snapshot_download
|
| 42 |
+
import chromadb
|
| 43 |
+
|
| 44 |
+
# 1. Download the database folder from Hugging Face
|
| 45 |
+
db_path = snapshot_download(
|
| 46 |
+
repo_id="Stephen-SMJ/RPKB",
|
| 47 |
+
repo_type="dataset",
|
| 48 |
+
allow_patterns="RPKB/*" # Adjust this if your folder name is different
|
| 49 |
+
)
|
| 50 |
+
|
| 51 |
+
# 2. Connect to the local ChromaDB instance
|
| 52 |
+
client = chromadb.PersistentClient(path=f"{db_path}/RPKB")
|
| 53 |
+
|
| 54 |
+
# 3. Access the specific collection
|
| 55 |
+
collection = client.get_collection(name="inference")
|
| 56 |
+
|
| 57 |
+
print(f"✅ Loaded {collection.count()} R functions ready for conditional retrieval!")
|
| 58 |
+
```
|
| 59 |
+
|
| 60 |
+
### 3. Perform a R Pakcage Retrieval
|
| 61 |
+
|
| 62 |
+
To retrieve the best function, make sure you encode your query using the DARE model.
|
| 63 |
+
|
| 64 |
+
```Python
|
| 65 |
+
from sentence_transformers import SentenceTransformer
|
| 66 |
+
|
| 67 |
+
# Load the DARE embedding model
|
| 68 |
+
model = SentenceTransformer("Stephen-SMJ/DARE-R-Retriever")
|
| 69 |
+
|
| 70 |
+
# Formulate the query with data constraints
|
| 71 |
+
user_query = "I have a high-dimensional genomic dataset named hidra_ex_1_2000.csv in my environment. I need to identify driver elements by estimating regulatory scores based on the counts provided
|
| 72 |
+
in the data. Please set the random seed to 123 at the start. I need to filter for fragment lengths between 150 and 600 bp and use a DNA count filter of 5. For my evaluation, please print the
|
| 73 |
+
first value of the estimated scores (est_a) for the very first region identified."
|
| 74 |
+
|
| 75 |
+
# Generate embedding
|
| 76 |
+
query_embedding = model.encode(user_query).tolist()
|
| 77 |
+
|
| 78 |
+
# Search in the database with Hard Filters
|
| 79 |
+
results = collection.query(
|
| 80 |
+
query_embeddings=[query_embedding],
|
| 81 |
+
n_results=3,
|
| 82 |
+
include=["metadatas", "distances", "documents"]
|
| 83 |
+
)
|
| 84 |
+
|
| 85 |
+
# Display Top-1 Result
|
| 86 |
+
print("Top-1 Function:", results["metadatas"][0][0]["package_name"], "::", results["metadatas"][0][0]["function_name"])
|
| 87 |
+
```
|