# vientofactory/semantic-search architecture

> Architecture diagram of the GitHub repository vientofactory/semantic-search, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-11). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/vientofactory/semantic-search
- Repository: https://github.com/vientofactory/semantic-search

## Overview

LawCast Semantic Search adds Korean-language semantic retrieval over legislative proposal notices, complementing keyword search. The main workflow reads notice data from SQLite or a JSONL snapshot, cleans and sections proposal text, chunks it, embeds the chunks, builds a FAISS index, and returns ranked results for a query. Separate branches support incremental artifact refresh, retrieval-quality evaluation, and an HTTP sidecar for backend callers. The README documents the pipeline and service behavior; some service-to-engine calls and evaluation wiring are not shown in the sampled source, so those links are omitted or marked unverified.

Main entry points: [`lawcast_semantic/search.py`](https://github.com/vientofactory/semantic-search/blob/main/lawcast_semantic/search.py) (Semantic searcher), [`lawcast_semantic/embedding.py`](https://github.com/vientofactory/semantic-search/blob/main/lawcast_semantic/embedding.py) (Korean embedder), [`lawcast_semantic/incremental.py`](https://github.com/vientofactory/semantic-search/blob/main/lawcast_semantic/incremental.py) (Incremental updater), [`lawcast_semantic/datasource.py`](https://github.com/vientofactory/semantic-search/blob/main/lawcast_semantic/datasource.py) (Notice datasource)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ingest["Notice preparation"]
  node_snapshot["Notice JSONL snapshot"]
  node_datasource["Notice datasource<br/>[datasource.py]"]
  node_preprocess["Text preprocessing<br/>[preprocess.py]"]
  node_chunking["Section-aware chunking<br/>[chunking.py]"]
end

subgraph group_pipeline["Vector pipeline"]
  node_chunks["Chunk records<br/>[config.py]"]
  node_embedder["Korean embedder<br/>[embedding.py]"]
  node_device["Device selection<br/>[device.py]"]
  node_embeddings["Embedding vectors<br/>[config.py]"]
  node_vector_index["FAISS vector index<br/>[indexing.py]"]
  node_index_artifacts["Index and ID map<br/>[config.py]"]
end

subgraph group_retrieval["Search and serving"]
  node_http_api["HTTP sidecar<br/>[app.py]"]
  node_searcher["Semantic searcher<br/>[search.py]"]
  node_aliases["Query aliases<br/>[aliases.py]"]
  node_ranked_results["Tiered ranked results<br/>[search.py]"]
end

subgraph group_operations["Refresh and evaluation"]
  node_update_runner["Scheduled update runner<br/>[update_runner.py]"]
  node_incremental["Incremental updater<br/>[incremental.py]"]
  node_evaluation["Retrieval evaluation<br/>[evaluation.py]"]
end

node_lawcast_db[("LawCast SQLite DB")]
node_query_user(("Search user"))
node_backend["LawCast backend"]

node_lawcast_db -->|"reads notices"| node_datasource
node_snapshot -->|"loads snapshot"| node_datasource
node_datasource -->|"supplies text"| node_preprocess
node_preprocess -->|"normalizes sections"| node_chunking
node_chunking -->|"writes chunks"| node_chunks
node_chunks -->|"embeds text"| node_embedder
node_device -->|"selects device"| node_embedder
node_embedder -->|"writes vectors"| node_embeddings
node_embeddings -->|"builds index"| node_vector_index
node_vector_index -->|"saves index"| node_index_artifacts
node_query_user -->|"submits query"| node_http_api
node_backend -->|"calls HTTP"| node_http_api
node_http_api -.->|"dispatches search"| node_searcher
node_searcher -->|"expands aliases"| node_aliases
node_searcher -->|"embeds query"| node_embedder
node_searcher -->|"ranks chunks"| node_vector_index
node_searcher -->|"returns ranking"| node_ranked_results
node_update_runner -->|"reads corpus"| node_datasource
node_update_runner -->|"plans refresh"| node_incremental
node_incremental -->|"rebuilds chunks"| node_chunking
node_incremental -.->|"embeds changed chunks"| node_embedder
node_incremental -->|"rewrites artifacts"| node_index_artifacts
node_evaluation -.->|"measures retrieval"| node_searcher

click node_snapshot "https://github.com/vientofactory/semantic-search/blob/main/data/sample_notices.jsonl"
click node_datasource "https://github.com/vientofactory/semantic-search/blob/main/lawcast_semantic/datasource.py"
click node_preprocess "https://github.com/vientofactory/semantic-search/blob/main/lawcast_semantic/preprocess.py"
click node_chunking "https://github.com/vientofactory/semantic-search/blob/main/lawcast_semantic/chunking.py"
click node_chunks "https://github.com/vientofactory/semantic-search/blob/main/lawcast_semantic/config.py"
click node_embedder "https://github.com/vientofactory/semantic-search/blob/main/lawcast_semantic/embedding.py"
click node_device "https://github.com/vientofactory/semantic-search/blob/main/lawcast_semantic/device.py"
click node_embeddings "https://github.com/vientofactory/semantic-search/blob/main/lawcast_semantic/config.py"
click node_vector_index "https://github.com/vientofactory/semantic-search/blob/main/lawcast_semantic/indexing.py"
click node_index_artifacts "https://github.com/vientofactory/semantic-search/blob/main/lawcast_semantic/config.py"
click node_http_api "https://github.com/vientofactory/semantic-search/blob/main/service/app.py"
click node_searcher "https://github.com/vientofactory/semantic-search/blob/main/lawcast_semantic/search.py"
click node_aliases "https://github.com/vientofactory/semantic-search/blob/main/lawcast_semantic/aliases.py"
click node_ranked_results "https://github.com/vientofactory/semantic-search/blob/main/lawcast_semantic/search.py"
click node_update_runner "https://github.com/vientofactory/semantic-search/blob/main/service/update_runner.py"
click node_incremental "https://github.com/vientofactory/semantic-search/blob/main/lawcast_semantic/incremental.py"
click node_evaluation "https://github.com/vientofactory/semantic-search/blob/main/lawcast_semantic/evaluation.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_snapshot,node_datasource,node_preprocess,node_chunking,node_query_user toneBlue
class node_chunks,node_embedder,node_device,node_embeddings,node_vector_index,node_index_artifacts,node_lawcast_db toneAmber
class node_http_api,node_searcher,node_aliases,node_ranked_results toneMint
class node_update_runner,node_incremental,node_evaluation toneRose
class node_backend toneIndigo
```

## Components

### Notice preparation

- [Notice JSONL snapshot](https://github.com/vientofactory/semantic-search/blob/main/data/sample_notices.jsonl): `data/sample_notices.jsonl`
- [Notice datasource](https://github.com/vientofactory/semantic-search/blob/main/lawcast_semantic/datasource.py): `lawcast_semantic/datasource.py`
- [Text preprocessing](https://github.com/vientofactory/semantic-search/blob/main/lawcast_semantic/preprocess.py): `lawcast_semantic/preprocess.py`
- [Section-aware chunking](https://github.com/vientofactory/semantic-search/blob/main/lawcast_semantic/chunking.py): `lawcast_semantic/chunking.py`

### Vector pipeline

- [Chunk records](https://github.com/vientofactory/semantic-search/blob/main/lawcast_semantic/config.py): `lawcast_semantic/config.py`
- [Korean embedder](https://github.com/vientofactory/semantic-search/blob/main/lawcast_semantic/embedding.py): `lawcast_semantic/embedding.py`
- [Device selection](https://github.com/vientofactory/semantic-search/blob/main/lawcast_semantic/device.py): `lawcast_semantic/device.py`
- [Embedding vectors](https://github.com/vientofactory/semantic-search/blob/main/lawcast_semantic/config.py): `lawcast_semantic/config.py`
- [FAISS vector index](https://github.com/vientofactory/semantic-search/blob/main/lawcast_semantic/indexing.py): `lawcast_semantic/indexing.py`
- [Index and ID map](https://github.com/vientofactory/semantic-search/blob/main/lawcast_semantic/config.py): `lawcast_semantic/config.py`

### Search and serving

- [HTTP sidecar](https://github.com/vientofactory/semantic-search/blob/main/service/app.py): `service/app.py`
- [Semantic searcher](https://github.com/vientofactory/semantic-search/blob/main/lawcast_semantic/search.py): `lawcast_semantic/search.py`
- [Query aliases](https://github.com/vientofactory/semantic-search/blob/main/lawcast_semantic/aliases.py): `lawcast_semantic/aliases.py`
- [Tiered ranked results](https://github.com/vientofactory/semantic-search/blob/main/lawcast_semantic/search.py): `lawcast_semantic/search.py`

### Refresh and evaluation

- [Scheduled update runner](https://github.com/vientofactory/semantic-search/blob/main/service/update_runner.py): `service/update_runner.py`
- [Incremental updater](https://github.com/vientofactory/semantic-search/blob/main/lawcast_semantic/incremental.py): `lawcast_semantic/incremental.py`
- [Retrieval evaluation](https://github.com/vientofactory/semantic-search/blob/main/lawcast_semantic/evaluation.py): `lawcast_semantic/evaluation.py`

### Other components

- **LawCast SQLite DB**
- **Search user**
- **LawCast backend**

## Connections

- LawCast SQLite DB → Notice datasource: reads notices (evidence: `README.md`)
- Notice JSONL snapshot → Notice datasource: loads snapshot (evidence: `README.md`)
- Notice datasource → Text preprocessing: supplies text (evidence: `scripts/01_preprocess_chunk.py`)
- Text preprocessing → Section-aware chunking: normalizes sections (evidence: `lawcast_semantic/chunking.py`)
- Section-aware chunking → Chunk records: writes chunks (evidence: `README.md`)
- Chunk records → Korean embedder: embeds text (evidence: `README.md`)
- Device selection → Korean embedder: selects device (evidence: `lawcast_semantic/embedding.py`)
- Korean embedder → Embedding vectors: writes vectors (evidence: `README.md`)
- Embedding vectors → FAISS vector index: builds index (evidence: `README.md`)
- FAISS vector index → Index and ID map: saves index (evidence: `README.md`)
- Search user → HTTP sidecar: submits query (evidence: `README.md`)
- LawCast backend → HTTP sidecar: calls HTTP (evidence: `README.md`)
- HTTP sidecar → Semantic searcher: dispatches search
- Semantic searcher → Query aliases: expands aliases (evidence: `lawcast_semantic/search.py`)
- Semantic searcher → Korean embedder: embeds query (evidence: `README.md`)
- Semantic searcher → FAISS vector index: ranks chunks (evidence: `lawcast_semantic/search.py`)
- Semantic searcher → Tiered ranked results: returns ranking (evidence: `README.md`)
- Scheduled update runner → Notice datasource: reads corpus (evidence: `service/update_runner.py`)
- Scheduled update runner → Incremental updater: plans refresh (evidence: `service/update_runner.py`)
- Incremental updater → Section-aware chunking: rebuilds chunks (evidence: `lawcast_semantic/incremental.py`)
- Incremental updater → Korean embedder: embeds changed chunks
- Incremental updater → Index and ID map: rewrites artifacts (evidence: `README.md`)
- Retrieval evaluation → Semantic searcher: measures retrieval
