Compare commits
16 Commits
8ec849b103
...
FEAT-minor
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5e0189be61 | ||
| fc6ceb558b | |||
| 676c86cf43 | |||
| 6810704173 | |||
| 4a1c67c518 | |||
| 3a4ac641cd | |||
| 861983531a | |||
| fe36ea6aaa | |||
|
|
62dd6de60c | ||
| d481b79465 | |||
| b8c65348e8 | |||
| d6902daa49 | |||
|
|
4f803c14f4 | ||
|
|
720d34b663 | ||
| a79c5ad1cc | |||
|
|
bf89c7544f |
95
README.md
95
README.md
@@ -1,99 +1,156 @@
|
|||||||
# Citation Sentinel
|
# Source Sentinel - 2025 @sjDev - LICENSE: MIT
|
||||||
|
|
||||||
A source-grounded research assistant that employs cosine similarity scoring for LLM-generated query responses to provide a "groundedness" score. This is a metric in Retrieval-Augmented Generation (RAG) systems that quantifies how well an AI-generated answer is supported by retrieved context. It measures "faithfulness" to source documents, ensuring the answer is not hallucinated or pulled from the model's pre-training data.
|
|
||||||
|
|
||||||
Users upload source documents, or provide links to online sources including audio/video (i.e. links to youtube videos). Users may then ask questions and receive answers (with inline citations) verifiably grounded in the provided information sources.
|

|
||||||
|
|
||||||
|
Image one: source-grounded research assistant for applied use of LLMs.
|
||||||
|
|
||||||
|
**Source Sentinel's value proposition: analyzing and conveniently working with large data corpora, when query-result accuracy is of the highest value. Examples include technical medical data exploration (reviewing health records, test results, or studies to find hidden patterns, trends, and answers), complex litigation (i.e. Patent/IP), advanced LLM development and refinement.**
|
||||||
|
|
||||||
|
Source Sentinel empowers users to transform an otherwise-unmanageably-large corpus of data on any topic of interest into refined, easily-digested subtopics and pose focused inquiries, to instantly receive concise, quantifiably-evaluated, accurate responses. The system also provides suggested follow-up questions further refining in user inquiries by detecting the query goals.
|
||||||
|
|
||||||
|
ALSO NOTE IN DEMO: clickable inline citations (in blue) that take user to source-grounded research basis/knowledge corpus supporting query response, with rated “groundedness” score.
|
||||||
|
|
||||||
|
|
||||||
|
# Reliability and Understandability
|
||||||
|
|
||||||
|
|
||||||
|
Source Sentinel's Retrieval-Augmented Generation (RAG) pipeline uses two-stage pass-through to Voyage AI embedding and ranking models, which uses cosine similarity methodology to scoring to evaluate query-source embeddings in multi-dimensional vector space. This yields a "groundedness" score.
|
||||||
|
|
||||||
|
|
||||||
|
Groundedness metrics quantify how well an AI-generated answer is supported by retrieved context. It measures "faithfulness" to source documents, ensuring the answer is not hallucinated, inaccurate or stale (pulled from the model's training data).
|
||||||
|
|
||||||
|
|
||||||
|
# Architecture - Basic Overview
|
||||||
|
|
||||||
|
|
||||||
|
Built with a React/Vite frontend and a Typescript/Node/Express backend, using Anthropic Claude for NL response generation, OpenAI Whisper for video audio track transcription, Voyage AI voyage-3 for embeddings and Voyage AI rerank-2 for response cosine similarity scoring (to generate the "groundedness" score) presented as an easily-understandable red/yellow/green "badge" style tooltip in the response (see image above.)
|
||||||
|
|
||||||
Built with a React/Vite frontend and a Typescript/Node/Express backend, using Anthropic Claude for generation, OpenAI Whisper for video audio track transcription, Voyage AI for embeddings and response cosine similarity scoring (the "groundedness" score).
|
|
||||||
|
|
||||||
## Query pipeline
|
## Query pipeline
|
||||||
|
|
||||||
|
|
||||||
Source Ingestion -> Parsing -> Chunking -> Embedding (using Voyage AI voyage-3 model) -> Storage (vector store) -> { user query submission } -> Evaluation of User Query -> Retrieval -> Ranking -> Response Generation (Using Anthopic's claude-opus-4-6 model) -> Response Groundedness Scoring (using Voyage AI rerank-r model)
|
Source Ingestion -> Parsing -> Chunking -> Embedding (using Voyage AI voyage-3 model) -> Storage (vector store) -> { user query submission } -> Evaluation of User Query -> Retrieval -> Ranking -> Response Generation (Using Anthopic's claude-opus-4-6 model) -> Response Groundedness Scoring (using Voyage AI rerank-r model)
|
||||||
|
|
||||||
|
## Why Database Math Can't Replace Groundedness Scoring
|
||||||
|
|
||||||
|
Many recent additions to the Vector database/store product space use distance metrics (Cosine, L2, Inner Product) for Bi-Encoder Similarity. They compare the vector of the user query against the vectors of chunks independently.
|
||||||
|
|
||||||
|
The rerank-r model at the end of the Source Sentinel pipeline performs Cross-Encoder Evaluation, taking two entirely separate text inputs:
|
||||||
|
|
||||||
|
1) The generated response from claude-opus-4-6 and
|
||||||
|
|
||||||
|
2) The raw source chunks
|
||||||
|
|
||||||
|
It processes them simultaneously through deep attention layers to check for hallucinations, missing context, and factual alignment.
|
||||||
|
|
||||||
|
A vector database cosine metric only calculates how close two embeddings are in coordinate space. It **does not read the generated text of a response to verify if it accurately reflects the source chunks**.
|
||||||
|
|
||||||
## Prerequisites
|
## Prerequisites
|
||||||
|
|
||||||
|
|
||||||
- **Node.js** (v18+)
|
- **Node.js** (v18+)
|
||||||
- **yt-dlp** -- Required for YouTube video source support (`brew install yt-dlp`)
|
- **yt-dlp** -- Required for YouTube video source support (`brew install yt-dlp`)
|
||||||
|
|
||||||
|
|
||||||
## Getting Started
|
## Getting Started
|
||||||
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# clone and install
|
# clone and install
|
||||||
git clone <repo-url> && cd citation_sentinel
|
git clone <repo-url> && cd citation_sentinel
|
||||||
cd server && npm install && cd ..
|
cd server && npm install && cd ..
|
||||||
cd client && npm install && cd ..
|
cd client && npm install && cd ..
|
||||||
|
|
||||||
|
|
||||||
# configure
|
# configure
|
||||||
cp server/.env.example server/.env
|
cp server/.env.example server/.env
|
||||||
# edit server/.env and add your ANTHROPIC_API_KEY, VOYAGE_API_KEY,
|
# edit server/.env and add your ANTHROPIC_API_KEY, VOYAGE_API_KEY,
|
||||||
# and optionally OPENAI_API_KEY (only needed for audio source transcription via Whisper)
|
# and optionally OPENAI_API_KEY (only needed for audio source transcription via Whisper)
|
||||||
|
|
||||||
|
|
||||||
# run
|
# run
|
||||||
make dev
|
make dev
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
## Rationale
|
## Rationale
|
||||||
|
|
||||||
|
|
||||||
This app demonstrates the core source-grounded Q&A pattern with transparent retrieval, generation, and groundedness scoring (LLM response quality cosine scoring) -- all with swappable models and is fully open source.
|
This app demonstrates the core source-grounded Q&A pattern with transparent retrieval, generation, and groundedness scoring (LLM response quality cosine scoring) -- all with swappable models and is fully open source.
|
||||||
|
|
||||||
|
|
||||||
## Methodology
|
## Methodology
|
||||||
|
|
||||||
|
|
||||||
This is a RAG (Retrieval-Augmented Generation) and query-response source-groundedness assurance system allowing users to create a research knowledge corpus, including:
|
This is a RAG (Retrieval-Augmented Generation) and query-response source-groundedness assurance system allowing users to create a research knowledge corpus, including:
|
||||||
|
|
||||||
|
|
||||||
1. Documents — PDFs, DOCX files, plain text audio files.
|
1. Documents — PDFs, DOCX files, plain text audio files.
|
||||||
2. Internet sources: via web URLs.
|
2. Internet sources: via web URLs.
|
||||||
2. Audio sources: i.e. YouTube videos, audio from which is transcribed to text.
|
2. Audio sources: i.e. YouTube videos, audio from which is transcribed to text.
|
||||||
|
|
||||||
|
|
||||||
These are then parsed, split into ~2000-character overlapping chunks, and converted into vector embeddings using Voyage AI's voyage-3 model.
|
These are then parsed, split into ~2000-character overlapping chunks, and converted into vector embeddings using Voyage AI's voyage-3 model.
|
||||||
|
|
||||||
|
|
||||||
The embeddings are stored in an in-memory vector store.
|
The embeddings are stored in an in-memory vector store.
|
||||||
|
|
||||||
|
|
||||||
When a user submits a query, the system enforces groundedness through a multi-layered strategy:
|
When a user submits a query, the system enforces groundedness through a multi-layered strategy:
|
||||||
|
|
||||||
1. **Retrieval constraint** — The query is embedded (via Voyage AI voyage-3) and compared against
|
|
||||||
stored chunk vectors using cosine similarity, returning the top 20 candidates.
|
|
||||||
|
|
||||||
2. **Reranking for precision** — Those 20 candidates are sent to Voyage AI's rerank-2 cross-encoder,
|
1. **Retrieval constraint** — The query is embedded (via Voyage AI voyage-3) and compared against stored chunk vectors using cosine similarity, returning the top 20 candidates.
|
||||||
which re-scores each query-chunk pair with deeper semantic analysis. Only the top 5 survive.
|
|
||||||
|
|
||||||
3. **Prompt-level constraint** — The top 5 chunks are passed to the "Primary LLM" (Claude opus-4-6)
|
|
||||||
for natural language query response.
|
|
||||||
The Primary LLM must cite sources using bracketed indices (e.g., [1], [2]) and admit when sources are
|
|
||||||
insufficient.
|
|
||||||
|
|
||||||
4. **Schema enforcement** — The Primary LLM's response is constrained to a JSON schema requiring structured
|
2. **Reranking for precision** — Those 20 candidates are sent to Voyage AI's rerank-2 cross-encoder, which re-scores each query-chunk pair with deeper semantic analysis. Only the top 5 survive.
|
||||||
fields (answer, citedSourceIndices, followUpQuestions). Any cited source indices that do not
|
|
||||||
correspond to real source groups are programmatically removed.
|
|
||||||
|
3. **Prompt-level constraint** — The top 5 chunks are passed to the "Primary LLM" (Claude opus-4-6) for natural language query response. The Primary LLM must cite sources using bracketed indices (e.g., [1], [2]) and admit when sources are insufficient.
|
||||||
|
|
||||||
|
|
||||||
|
4. **Schema enforcement** — The Primary LLM's response is constrained to a JSON schema requiring structured fields (answer, citedSourceIndices, followUpQuestions). Any cited source indices that do not correspond to real source groups are programmatically removed.
|
||||||
|
|
||||||
|
|
||||||
|
5. **Post-generation groundedness scoring** — The answer is split into individual sentences. Voyage AI voyage-3 embeds each sentence, and compares it (using cosine similarity) against the vectors of the cited chunks. The similarity is calibrated to a 0–1 scale and averaged, producing a groundedness score surfaced to the user with a visual indicator (“badge” in green/yellow/red).
|
||||||
|
|
||||||
5. **Post-generation groundedness scoring** — The answer is split into individual sentences. Voyage
|
|
||||||
AI voyage-3 embeds each sentence, and compares it (using cosine similarity) against the vectors
|
|
||||||
of the cited chunks. The similarity is calibrated to a 0–1 scale and averaged, producing a single
|
|
||||||
groundedness score that is surfaced to the user with a visual indicator (green/yellow/red).
|
|
||||||
|
|
||||||
## Similarity Metrics for Semantic Understanding
|
## Similarity Metrics for Semantic Understanding
|
||||||
|
|
||||||
|
|
||||||
Cosine similarity measures how closely two vectors (representing data like words, images, or preferences) are aligned in a multi-dimensional space by calculating the cosine of the angle between them.
|
Cosine similarity measures how closely two vectors (representing data like words, images, or preferences) are aligned in a multi-dimensional space by calculating the cosine of the angle between them.
|
||||||
|
|
||||||
|
|
||||||
Archetypical cosine scores range from -1 to 1.
|
Archetypical cosine scores range from -1 to 1.
|
||||||
|
|
||||||
|
|
||||||
1: Vectors point in the exact same direction (highly similar).
|
1: Vectors point in the exact same direction (highly similar).
|
||||||
0: Vectors are at a 90-degree angle (orthogonal/unrelated).
|
0: Vectors are at a 90-degree angle (orthogonal/unrelated).
|
||||||
-1: Vectors point in opposite directions.
|
-1: Vectors point in opposite directions.
|
||||||
|
|
||||||
|
|
||||||
Cosine distance between high-dimensional text embeddings is compressed: unrelated notes sit close to orthogonal, so both the within-cluster and nearest-cluster distances land near 0.8. In this application, scores are normalized to a bounded range wherein unrelated query-response pair scores are nearly orthogonal.
|
Cosine distance between high-dimensional text embeddings is compressed: unrelated notes sit close to orthogonal, so both the within-cluster and nearest-cluster distances land near 0.8. In this application, scores are normalized to a bounded range wherein unrelated query-response pair scores are nearly orthogonal.
|
||||||
|
|
||||||
|
|
||||||
## Design
|
## Design
|
||||||
|
|
||||||
|
|
||||||
Two-package monorepo:
|
Two-package monorepo:
|
||||||
|
|
||||||
|
|
||||||
- `server/` -- single Express backend with layered architecture (routes -> services -> stores). Routes orchestrate; services contain business logic; stores manage in-memory state.
|
- `server/` -- single Express backend with layered architecture (routes -> services -> stores). Routes orchestrate; services contain business logic; stores manage in-memory state.
|
||||||
|
|
||||||
|
|
||||||
- `client/` -- React 19 SPA via Vite. Two-panel layout: sidebar for data sources, main area for LLM chat with explorable citations, groundedness badges (cosine similarity scoring of LLM responses), and follow-up question chips.
|
- `client/` -- React 19 SPA via Vite. Two-panel layout: sidebar for data sources, main area for LLM chat with explorable citations, groundedness badges (cosine similarity scoring of LLM responses), and follow-up question chips.
|
||||||
|
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
|
|
||||||
MIT. See [LICENSE](./LICENSE).
|
MIT. See [LICENSE](./LICENSE).
|
||||||
|
|
||||||
|
|
||||||
## Author
|
## Author
|
||||||
|
|
||||||
|
|
||||||
@sjdev
|
@sjdev
|
||||||
|
|||||||
BIN
sample screen scaps/DEMO FOR SOURCE SENT.jpg
Normal file
BIN
sample screen scaps/DEMO FOR SOURCE SENT.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 365 KiB |
BIN
sample screen scaps/DEMO FOR SOURCE SENT_SMALL.jpg
Normal file
BIN
sample screen scaps/DEMO FOR SOURCE SENT_SMALL.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 133 KiB |
BIN
sample screen scaps/SMALL_DEMO FOR SOURCE SENT.jpg
Normal file
BIN
sample screen scaps/SMALL_DEMO FOR SOURCE SENT.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 157 KiB |
BIN
sample screen scaps/Screenshot 2026-08-03 at 12.03.34 AM.png
Normal file
BIN
sample screen scaps/Screenshot 2026-08-03 at 12.03.34 AM.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 307 KiB |
BIN
sample screen scaps/Screenshot 2026-08-03 at 12.04.10 AM.png
Normal file
BIN
sample screen scaps/Screenshot 2026-08-03 at 12.04.10 AM.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 309 KiB |
@@ -104,11 +104,11 @@ export async function generateStudyGuide(sourceGroups: SourceGroup[]): Promise<S
|
|||||||
const sources = buildSourceBlock(sourceGroups);
|
const sources = buildSourceBlock(sourceGroups);
|
||||||
const start = Date.now();
|
const start = Date.now();
|
||||||
|
|
||||||
const prompt = `You are an expert educator. Given the source documents below, produce a comprehensive study guide. Follow these rules:
|
const prompt = `You are an expert reasearch assistant. Given the source documents below, produce a comprehensive guide. Follow these rules:
|
||||||
|
|
||||||
1. Create a structured outline of the main ideas organized into logical sections.
|
1. Create a structured outline of the main ideas organized into logical sections.
|
||||||
2. For each section, provide: bullet-point key concepts, key terms with definitions, and 2-3 self-review questions.
|
2. For each section, provide: bullet-point key concepts, key terms with definitions, and 2-3 self-review questions.
|
||||||
3. At the end, provide mnemonic devices or simplified restatements to help memorize the hardest concepts.
|
3. At the end, provide mnemonic devices or simplified restatements of the hardest concepts.
|
||||||
4. Be concise but thorough. Use simple, clear language.
|
4. Be concise but thorough. Use simple, clear language.
|
||||||
|
|
||||||
--- SOURCE DOCUMENTS ---
|
--- SOURCE DOCUMENTS ---
|
||||||
|
|||||||
Reference in New Issue
Block a user