Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/pr-review-prompt.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ function process(data: Data | null) {

### Naming Conventions

- **Classes and Types**: PascalCase (`Reranker`, `LlmClient`)
- **Classes and Types**: PascalCase (`Intent`, `LlmClient`)
- **Functions and Variables**: camelCase (`buildMessages`, `candidateKey`)
- **Constants**: UPPER_SNAKE_CASE (`BATCH_SIZE`, `TIMEOUT_MS`)
- **Test files**: `*.unit.test.ts` or `*.int.test.ts`
Expand Down
8 changes: 5 additions & 3 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Intent is a TypeScript library that uses LLMs to rerank arbitrary items based on

### Core Reranking Flow

The `Reranker` class orchestrates the entire reranking process:
The `Intent` class orchestrates the entire ranking process:

1. **Preparation** (`prepareCandidates`): Normalizes items into a consistent shape with key/summary/index
2. **Batching** (`batchProcess` in batches.ts): Splits candidates into batches, merges tiny trailing batches to avoid inefficient LLM calls
Expand All @@ -75,14 +75,16 @@ All config lives in config.ts using lib/config helpers:
- Environment variables: `INTENT_MODEL`, `INTENT_TIMEOUT_MS`, `INTENT_RELEVANCY_THRESHOLD`, `INTENT_BATCH_SIZE`, `INTENT_TINY_BATCH_FRACTION`
- Groq-specific: `GROQ_API_KEY`, `GROQ_DEFAULT_MODEL`, `GROQ_DEFAULT_TEMPERATURE`
- Config is loaded automatically via `dotenv/config` import at top of config.ts
- Reranker constructor accepts overrides as third parameter
- Intent constructor accepts options as a single optional object

**Config Naming Convention**: By design, config keys in `CONFIG` use `UPPER_SNAKE_CASE` to mirror their environment variable names (e.g., `CONFIG.INTENT.MODEL` matches `INTENT_MODEL`). The user-facing API uses `camelCase` (e.g., `options.model`). This intentional distinction keeps config keys aligned with environment variables while providing an ergonomic API. Internal code converts between these formats as needed.

### Key Design Patterns

- **Stable fallbacks**: Any failure (LLM error, timeout, invalid response) returns items in original order
- **Duplicate key handling**: Internal disambiguation using `"Key (idx)"` suffix
- **Strict typing**: Uses TypeScript strict mode with `noUncheckedIndexedAccess`, `exactOptionalPropertyTypes`
- **Generic item support**: Reranker is `Reranker<T>` with user-provided key/summary extractors
- **Generic item support**: Intent is `Intent<T>` with user-provided key/summary extractors
- **Zero/one-item fast path**: Avoids LLM calls when unnecessary

## Testing Strategy
Expand Down
Loading