feat(docs): document note ID and collisions

This commit is contained in:
Elian Doran 2025-04-05 00:06:45 +03:00
parent bb23ae6813
commit 78fba191e1
No known key found for this signature in database
6 changed files with 58 additions and 19 deletions

View File

@ -3815,14 +3815,6 @@
"mime": "image/jpg", "mime": "image/jpg",
"position": 10, "position": 10,
"dataFileName": "Text_image.png" "dataFileName": "Text_image.png"
},
{
"attachmentId": "yGknq3nsWpef",
"title": "bx-edit-alt.svg",
"role": "image",
"mime": "image/svg+xml",
"position": 10,
"dataFileName": "Text_bx-edit-alt.svg"
} }
], ],
"dirFileName": "Text", "dirFileName": "Text",
@ -8109,6 +8101,13 @@
"value": "bx bx-hash", "value": "bx bx-hash",
"isInheritable": false, "isInheritable": false,
"position": 10 "position": 10
},
{
"type": "relation",
"name": "internalLink",
"value": "0vhv7lsOLy82",
"isInheritable": false,
"position": 20
} }
], ],
"format": "markdown", "format": "markdown",

View File

@ -0,0 +1,16 @@
# Note ID
Whereas some applications use file names to uniquely identify notes, Trilium uses the concept of Note ID.
Generally, the Note ID is a 12-character long alphanumeric sequence (including both lower and upper case letter) that is randomly generated for each new note.
## How does the import/export affect the note IDs
When notes are exported, their note ID is kept in the metadata of the export. However when they are imported back in, a new note ID is generated for all the notes. This also includes other entities that are part of the import/export process such as [Attachments](../Basic%20Concepts%20and%20Features/Notes/Attachments.md).
## Note collisions
Since the Note ID is a fixed-width randomly generated number, due to the [pigeonhole principle](https://en.wikipedia.org/wiki/Pigeonhole_principle), there is a possibility that a newly created note will have the same ID as an existing note.
Since the note ID is alphanumeric and the length is 12 we have \\(62^{12}\\) unique IDs. However since we are generating them randomly, we can use a collision calculator such as the one for [Nano ID](https://alex7kom.github.io/nano-nanoid-cc/?alphabet=0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz&size=12&speed=1000&speedUnit=hour) to determine that we'd need to create 1000 notes per hour every hour for 9 centuries in order to have at least 1% probability of a note collision.
As such, Trilium does not take any explicit action against potential note collisions, similar to other software that makes uses of unique hashes such as [Git](https://stackoverflow.com/questions/10434326/hash-collision-in-git). If one would theoretically occur, what would most likely happen is that the existing note will be replaced by the new one.

View File

@ -1 +0,0 @@
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path d="M19.045 7.401c.378-.378.586-.88.586-1.414s-.208-1.036-.586-1.414l-1.586-1.586c-.378-.378-.88-.586-1.414-.586s-1.036.208-1.413.585L4 13.585V18h4.413L19.045 7.401zm-3-3 1.587 1.585-1.59 1.584-1.586-1.585 1.589-1.584zM6 16v-1.585l7.04-7.018 1.586 1.586L7.587 16H6zm-2 4h16v2H4z"/></svg>

Before

Width:  |  Height:  |  Size: 377 B

View File

@ -3815,14 +3815,6 @@
"mime": "image/jpg", "mime": "image/jpg",
"position": 10, "position": 10,
"dataFileName": "Text_image.png" "dataFileName": "Text_image.png"
},
{
"attachmentId": "yGknq3nsWpef",
"title": "bx-edit-alt.svg",
"role": "image",
"mime": "image/svg+xml",
"position": 10,
"dataFileName": "Text_bx-edit-alt.svg"
} }
], ],
"dirFileName": "Text", "dirFileName": "Text",
@ -8109,6 +8101,13 @@
"value": "bx bx-hash", "value": "bx bx-hash",
"isInheritable": false, "isInheritable": false,
"position": 10 "position": 10
},
{
"type": "relation",
"name": "internalLink",
"value": "0vhv7lsOLy82",
"isInheritable": false,
"position": 20
} }
], ],
"format": "html", "format": "html",

View File

@ -12,7 +12,34 @@
<div class="content"> <div class="content">
<h1 data-trilium-h1>Note ID</h1> <h1 data-trilium-h1>Note ID</h1>
<div class="ck-content"></div> <div class="ck-content">
<p>Whereas some applications use file names to uniquely identify notes, Trilium
uses the concept of Note ID.</p>
<p>Generally, the Note ID is a 12-character long alphanumeric sequence (including
both lower and upper case letter) that is randomly generated for each new
note.</p>
<h2>How does the import/export affect the note IDs</h2>
<p>When notes are exported, their note ID is kept in the metadata of the
export. However when they are imported back in, a new note ID is generated
for all the notes. This also includes other entities that are part of the
import/export process such as&nbsp;<a class="reference-link" href="../Basic%20Concepts%20and%20Features/Notes/Attachments.html">Attachments</a>.</p>
<h2>Note collisions</h2>
<p>Since the Note ID is a fixed-width randomly generated number, due to the
<a
href="https://en.wikipedia.org/wiki/Pigeonhole_principle">pigeonhole principle</a>, there is a possibility that a newly created
note will have the same ID as an existing note.</p>
<p>Since the note ID is alphanumeric and the length is 12 we have&nbsp;
<span
class="math-tex">\(62^{12}\)</span>&nbsp;unique IDs. However since we are generating them
randomly, we can use a collision calculator such as the one for <a href="https://alex7kom.github.io/nano-nanoid-cc/?alphabet=0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz&amp;size=12&amp;speed=1000&amp;speedUnit=hour">Nano ID</a> to
determine that we'd need to create 1000 notes per hour every hour for 9
centuries in order to have at least 1% probability of a note collision.</p>
<p>As such, Trilium does not take any explicit action against potential note
collisions, similar to other software that makes uses of unique hashes
such as <a href="https://stackoverflow.com/questions/10434326/hash-collision-in-git">Git</a>.
If one would theoretically occur, what would most likely happen is that
the existing note will be replaced by the new one.</p>
</div>
</div> </div>
</body> </body>

View File

@ -1 +0,0 @@
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path d="M19.045 7.401c.378-.378.586-.88.586-1.414s-.208-1.036-.586-1.414l-1.586-1.586c-.378-.378-.88-.586-1.414-.586s-1.036.208-1.413.585L4 13.585V18h4.413L19.045 7.401zm-3-3 1.587 1.585-1.59 1.584-1.586-1.585 1.589-1.584zM6 16v-1.585l7.04-7.018 1.586 1.586L7.587 16H6zm-2 4h16v2H4z"/></svg>

Before

Width:  |  Height:  |  Size: 377 B