Datasets:
File size: 6,882 Bytes
5a1aad2 fe0f01b 48cf2db fe0f01b 48cf2db fe0f01b 48cf2db 5a1aad2 fe0f01b 29c33f5 fe0f01b 29c33f5 fe0f01b 29c33f5 fe0f01b | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 | ---
license: etalab-2.0
language:
- fr
tags:
- legal
- french-law
- embeddings
- legifrance
- mistral
size_categories:
- 10K<n<100K
---
# Open Codes
Open dataset of French legal code articles with embeddings.
Chunked articles from French legal codes sourced from
[Legifrance](https://www.legifrance.gouv.fr/) via the PISTE API,
with 1024-dimensional embeddings generated by Mistral AI.
Each row is a text chunk enriched with full article metadata from the parent
legal code article.
## Dataset Description
- **Source**: [PISTE Legifrance API](https://piste.gouv.fr/) (official French government legal database)
- **License**: [Licence Ouverte / Etalab 2.0](https://www.etalab.gouv.fr/licence-ouverte-open-licence/)
- **Embeddings**: Mistral AI `mistral-embed` (1024 dimensions)
- **Update frequency**: Daily (nightly sync at 02:00 UTC, dataset push at 06:00 UTC)
- **Codes**: Dynamically sourced from `LEX_codes_piste` (active codes only)
- **Quality**: Dedup + stale-chunk filtering applied before every push
### Legal codes included
The list of legal codes is dynamic and managed in the `LEX_codes_piste` table.
Adding a new code there (with `actif=true`) automatically includes it in the next sync and export.
## Schema
### Chunk fields
| Column | Type | Description |
|--------|------|-------------|
| `chunk_text` | string | Text content of the chunk |
| `embedding` | float32[1024] | Mistral AI embedding vector |
| `id_legifrance` | string | Legifrance article identifier |
| `code_name` | string | Human-readable code name (e.g. "Code civil") |
| `chunk_index` | int32 | Chunk position within the article (0-indexed) |
| `start_position` | int32 | Character offset in original article text |
| `end_position` | int32 | End character offset in original article text |
| `code` | string | Legal code identifier (e.g. LEGITEXT000006070721) |
| `num` | string | Article number (e.g. "L. 1234-5") |
| `etat` | string | Article status (VIGUEUR, ABROGE, etc.) |
| `fullSectionsTitre` | string | Full hierarchy path in the code |
### Article metadata fields (prefixed `article_`)
#### Identifiers
| Column | Type | Description |
|--------|------|-------------|
| `article_id_legifrance` | string | Legifrance article ID |
| `article_code` | string | Legal code ID |
| `article_num` | string | Article number |
| `article_cid` | string | Consolidated ID |
| `article_idEli` | string | ELI (European Legislation Identifier) |
| `article_idEliAlias` | string | ELI alias |
| `article_idTexte` | string | Text ID |
| `article_cidTexte` | string | Consolidated text ID |
#### Content
| Column | Type | Description |
|--------|------|-------------|
| `article_texte` | string | Full article plain text |
| `article_texteHtml` | string | Full article HTML |
| `article_nota` | string | Article notes (plain text) |
| `article_notaHtml` | string | Article notes (HTML) |
| `article_surtitre` | string | Article subtitle |
| `article_historique` | string | Article history |
#### Dates & Status
**Date format**: `article_dateDebut` and `article_dateFin` are stored as **Unix timestamps in milliseconds** (string type). This is the raw format returned by the Legifrance PISTE API.
To convert to a human-readable date in Python:
```python
from datetime import datetime, timezone
timestamp_ms = "1301529600000"
dt = datetime.fromtimestamp(int(timestamp_ms) / 1000, tz=timezone.utc)
print(dt) # 2011-03-31 00:00:00+00:00
```
Special value: `32472144000000` (year 2999) means "no end date" — the article is in force indefinitely.
| Column | Type | Description |
|--------|------|-------------|
| `article_dateDebut` | string | Effective start date (Unix ms) |
| `article_dateFin` | string | Effective end date (Unix ms, `32472144000000` = indefinite) |
| `article_dateDebutExtension` | string | Extension start date (Unix ms) |
| `article_dateFinExtension` | string | Extension end date (Unix ms) |
| `article_etat` | string | Status: `VIGUEUR` (in force), `ABROGE` (repealed), etc. |
| `article_type_article` | string | Article type |
| `article_nature` | string | Legal nature |
| `article_origine` | string | Origin (e.g. `LEGI`) |
| `article_version_article` | string | Version identifier |
| `article_versionPrecedente` | string | Previous version ID |
| `article_multipleVersions` | bool | Has multiple versions |
#### Hierarchy
| Column | Type | Description |
|--------|------|-------------|
| `article_sectionParentId` | string | Parent section ID |
| `article_sectionParentCid` | string | Parent section consolidated ID |
| `article_sectionParentTitre` | string | Parent section title |
| `article_fullSectionsTitre` | string | Full hierarchy path |
| `article_ordre` | int32 | Sort order within the code |
| `article_partie` | string | Partie (e.g. "Partie legislative") |
| `article_livre` | string | Livre |
| `article_titre` | string | Titre |
| `article_chapitre` | string | Chapitre |
| `article_section` | string | Section |
| `article_sous_section` | string | Sous-section |
| `article_paragraphe` | string | Paragraphe |
#### Extras
| Column | Type | Description |
|--------|------|-------------|
| `article_infosComplementaires` | string | Additional info (plain text) |
| `article_infosComplementairesHtml` | string | Additional info (HTML) |
| `article_conditionDiffere` | string | Deferred condition |
| `article_infosRestructurationBranche` | string | Branch restructuring info |
| `article_infosRestructurationBrancheHtml` | string | Branch restructuring (HTML) |
| `article_renvoi` | string | Cross-references |
| `article_comporteLiensSP` | bool | Contains SP links |
| `article_idTechInjection` | string | Technical injection ID |
| `article_refInjection` | string | Injection reference |
| `article_numeroBo` | string | BO number |
| `article_inap` | string | INAP code |
## Usage
```python
from datasets import load_dataset
from datetime import datetime, timezone
ds = load_dataset("ArthurSrz/open_codes", split="train")
# Access a chunk with its embedding and article metadata
row = ds[0]
print(row["code_name"]) # e.g. "Code civil"
print(row["chunk_text"][:200])
print(len(row["embedding"])) # 1024
# Convert dates from Unix ms to datetime
date_debut = datetime.fromtimestamp(int(row["article_dateDebut"]) / 1000, tz=timezone.utc)
print(date_debut) # e.g. 2011-03-31 00:00:00+00:00
# Filter by legal code
code_civil = ds.filter(lambda x: x["code_name"] == "Code civil")
# Filter active articles only
en_vigueur = ds.filter(lambda x: x["article_etat"] == "VIGUEUR")
# Use embeddings for semantic search
import numpy as np
query_emb = np.array(ds[0]["embedding"])
```
## Provenance
Built by the [marIAnne](https://github.com/ArthurSrz/open_codes) project.
Sync pipeline fetches articles nightly from PISTE Legifrance, chunks them,
and generates embeddings via Mistral AI.
|