Denser Retriever

Quick Start

This guide will help you get started with Denser Retriever in just a few minutes. You'll learn how to install the SDK, create a knowledge base, ingest documents, and perform semantic searches.

Installation

npm install @denserai/retriever-sdk
pip install denser-retriever-sdk

Initialize the Client

First, initialize the Denser Retriever client with your API key:

import { DenserRetriever } from "@denserai/retriever-sdk";

const client = new DenserRetriever({ apiKey: "YOUR_API_KEY" });
from denser_retriever import DenserRetriever

client = DenserRetriever(api_key="YOUR_API_KEY")

Never hardcode your API key in production code. Use environment variables instead.

Complete Workflow

Follow these steps to build your first semantic search application:

Create a Knowledge Base

Knowledge bases are containers for your documents. Create one to organize related content:

const kbRes = await client.createKnowledgeBase(
  "Product Documentation", // Name
  "All product-related docs" // Description
);
const kbId = kbRes.data.id;
console.log(`Created knowledge base: ${kbId}`);
kb = client.create_knowledge_base(
    name="Product Documentation",
    description="All product-related docs"
)
kb_id = kb["data"]["id"]
print(f"Created knowledge base: {kb_id}")

Ingest Documents

You can ingest documents in two ways: file upload or raw text import.

Option A: Import Raw Text

The simplest way to add content:

await client.importTextContentAndPoll(
  kbId,
  "Getting Started Guide", // Title
  "Denser Retriever is a semantic search platform that enables..." // Content
);
client.import_text_content_and_poll(
    knowledge_base_id=kb_id,
    title="Getting Started Guide",
    content="Denser Retriever is a semantic search platform that enables..."
)

Option B: Upload Files (PDF, DOCX, etc.)

For file uploads, use the 3-step process:

import fs from "fs";
import axios from "axios";

// 1. Get presigned upload URL
const fileName = "manual.pdf";
const stats = fs.statSync("./manual.pdf");
const presignRes = await client.presignUploadUrl(kbId, fileName, stats.size);
const { fileId, uploadUrl } = presignRes.data;

// 2. Upload file to S3
const fileStream = fs.createReadStream("./manual.pdf");
await axios.put(uploadUrl, fileStream, {
  headers: {
    "Content-Type": "application/octet-stream",
    "Content-Length": stats.size,
  },
});

// 3. Import and wait for processing
const result = await client.importFileAndPoll(fileId);
console.log("Document status:", result.data.status);
import os
import requests

file_path = "./manual.pdf"
file_size = os.path.getsize(file_path)
file_name = os.path.basename(file_path)

# 1. Get presigned upload URL
presign = client.presign_upload_url(
    knowledge_base_id=kb_id,
    file_name=file_name,
    size=file_size
)
file_id = presign["data"]["fileId"]
upload_url = presign["data"]["uploadUrl"]

# 2. Upload file
with open(file_path, "rb") as f:
    requests.put(upload_url, data=f, headers={"Content-Type": "application/octet-stream"})

# 3. Import and wait for processing
result = client.import_file_and_poll(file_id)
print("Document status:", result["data"]["status"])

Search Your Documents

Perform semantic search across your knowledge base:

const searchRes = await client.query("How do I get started?", {
  knowledgeBaseIds: [kbId], // Optional: filter by knowledge bases
  limit: 5, // Optional: limit results (default: 10, max: 50)
});

searchRes.data.forEach((item) => {
  console.log(`[Score: ${item.score.toFixed(3)}] ${item.content}`);
});
results = client.query(
    query="How do I get started?",
    knowledge_base_ids=[kb_id],  # Optional: filter by knowledge bases
    limit=5,  # Optional: limit results (default: 10, max: 50)
)

for item in results["data"]:
    print(f"[Score: {item['score']:.3f}] {item['content']}")

Knowledge Base Management

List Knowledge Bases

const listRes = await client.listKnowledgeBases();
listRes.data.forEach((kb) => {
  console.log(`${kb.name} (${kb.id})`);
});
kbs = client.list_knowledge_bases()
for kb in kbs["data"]:
    print(f"{kb['name']} ({kb['id']})")

Update Knowledge Base

await client.updateKnowledgeBase(kbId, {
  name: "Updated Documentation",
  description: "New description",
});
client.update_knowledge_base(
    knowledge_base_id=kb_id,
    name="Updated Documentation",
    description="New description"
)

Delete Knowledge Base

await client.deleteKnowledgeBase(kbId);
client.delete_knowledge_base(kb_id)

Deleting a knowledge base will permanently remove all associated documents. This action cannot be undone.

Account Management

Check Usage

const usage = await client.getUsage();
console.log(`Knowledge bases: ${usage.data.knowledgeBaseCount}`);
console.log(`Storage used: ${usage.data.storageUsed} bytes`);
usage = client.get_usage()
print(f"Knowledge bases: {usage['data']['knowledgeBaseCount']}")
print(f"Storage used: {usage['data']['storageUsed']} bytes")

Check Credit Balance

const balance = await client.getBalance();
console.log(`Credit balance: ${balance.data.balance}`);
balance = client.get_balance()
print(f"Credit balance: {balance['data']['balance']}")

Next Steps

On this page