basic-memory 0.23.3.dev1__py3-none-any.whl → 0.23.3.dev3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- basic_memory/indexing/batch_indexer.py +8 -1
- basic_memory/indexing/index_batch_runtime.py +2 -0
- basic_memory/markdown/plugins.py +123 -22
- {basic_memory-0.23.3.dev1.dist-info → basic_memory-0.23.3.dev3.dist-info}/METADATA +1 -1
- {basic_memory-0.23.3.dev1.dist-info → basic_memory-0.23.3.dev3.dist-info}/RECORD +8 -8
- {basic_memory-0.23.3.dev1.dist-info → basic_memory-0.23.3.dev3.dist-info}/WHEEL +0 -0
- {basic_memory-0.23.3.dev1.dist-info → basic_memory-0.23.3.dev3.dist-info}/entry_points.txt +0 -0
- {basic_memory-0.23.3.dev1.dist-info → basic_memory-0.23.3.dev3.dist-info}/licenses/LICENSE +0 -0
|
@@ -159,11 +159,14 @@ class BatchIndexer:
|
|
|
159
159
|
*,
|
|
160
160
|
max_concurrent: int,
|
|
161
161
|
parse_max_concurrent: int | None = None,
|
|
162
|
+
metadata_update_max_concurrent: int | None = None,
|
|
162
163
|
existing_permalink_by_path: dict[str, str | None] | None = None,
|
|
163
164
|
) -> IndexingBatchResult:
|
|
164
165
|
"""Index one batch of loaded files with bounded concurrency."""
|
|
165
166
|
if max_concurrent <= 0:
|
|
166
167
|
raise ValueError("max_concurrent must be greater than zero")
|
|
168
|
+
if metadata_update_max_concurrent is not None and metadata_update_max_concurrent <= 0:
|
|
169
|
+
raise ValueError("metadata_update_max_concurrent must be greater than zero")
|
|
167
170
|
|
|
168
171
|
ordered_paths = sorted(files)
|
|
169
172
|
if not ordered_paths:
|
|
@@ -220,7 +223,11 @@ class BatchIndexer:
|
|
|
220
223
|
|
|
221
224
|
refreshed, refresh_errors = await self._run_bounded(
|
|
222
225
|
[path for path in ordered_paths if path in prepared_entities],
|
|
223
|
-
limit=
|
|
226
|
+
limit=(
|
|
227
|
+
self.app_config.index_metadata_update_max_concurrent
|
|
228
|
+
if metadata_update_max_concurrent is None
|
|
229
|
+
else metadata_update_max_concurrent
|
|
230
|
+
),
|
|
224
231
|
worker=lambda path: self._refresh_search_index(
|
|
225
232
|
prepared_entities[path],
|
|
226
233
|
entities_by_id[prepared_entities[path].entity_id],
|
|
@@ -56,6 +56,7 @@ class IndexInputBatchExecutor(Protocol):
|
|
|
56
56
|
*,
|
|
57
57
|
max_concurrent: int,
|
|
58
58
|
parse_max_concurrent: int | None = None,
|
|
59
|
+
metadata_update_max_concurrent: int | None = None,
|
|
59
60
|
) -> IndexingBatchResult:
|
|
60
61
|
"""Index one batch of storage-neutral input files."""
|
|
61
62
|
|
|
@@ -105,6 +106,7 @@ class IndexBatchRuntime[EntityT: IndexedNoteContentEntity, FileInfoT: LoadedInde
|
|
|
105
106
|
input_files,
|
|
106
107
|
max_concurrent=max_concurrent,
|
|
107
108
|
parse_max_concurrent=parse_max_concurrent,
|
|
109
|
+
metadata_update_max_concurrent=metadata_update_max_concurrent,
|
|
108
110
|
)
|
|
109
111
|
reconciliation = await reconcile_indexed_note_content_batch(
|
|
110
112
|
result.indexed,
|
basic_memory/markdown/plugins.py
CHANGED
|
@@ -5,6 +5,7 @@ from typing import List, Any, Dict
|
|
|
5
5
|
|
|
6
6
|
from basic_memory.utils import normalize_project_reference
|
|
7
7
|
from markdown_it import MarkdownIt
|
|
8
|
+
from markdown_it.rules_inline.backticks import backtick
|
|
8
9
|
from markdown_it.token import Token
|
|
9
10
|
|
|
10
11
|
# Transcript timecodes like [00:00:11] or [1:02:03.500] share the bracket shape of
|
|
@@ -127,6 +128,84 @@ def parse_observation(token: Token) -> Dict[str, Any]:
|
|
|
127
128
|
|
|
128
129
|
|
|
129
130
|
# Relation handling functions
|
|
131
|
+
def _relation_content(token: Token) -> str:
|
|
132
|
+
"""Return the source content of an inline token."""
|
|
133
|
+
return token.tag or token.content
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
_CODE_SPANS_KEY = "basic_memory_code_spans"
|
|
137
|
+
_CODE_SPAN_PARSER = MarkdownIt()
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
def _record_inline_code_span(state: Any, silent: bool) -> bool:
|
|
141
|
+
"""Delegate to MarkdownIt and retain exact source spans for code tokens."""
|
|
142
|
+
start = state.pos
|
|
143
|
+
token_count = len(state.tokens)
|
|
144
|
+
matched = backtick(state, silent)
|
|
145
|
+
if matched and not silent and len(state.tokens) > token_count:
|
|
146
|
+
if state.tokens[-1].type == "code_inline":
|
|
147
|
+
state.env[_CODE_SPANS_KEY].append((start, state.pos))
|
|
148
|
+
return matched
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
_CODE_SPAN_PARSER.inline.ruler.at("backticks", _record_inline_code_span)
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
def _inline_code_spans(content: str) -> list[tuple[int, int]]:
|
|
155
|
+
"""Return source ranges that MarkdownIt classifies as inline code.
|
|
156
|
+
|
|
157
|
+
This delegates delimiter and escape handling to the same MarkdownIt inline
|
|
158
|
+
rule used by the document parser instead of duplicating CommonMark's
|
|
159
|
+
backtick scanner. It also preserves MarkdownIt's linear-time cache for
|
|
160
|
+
unmatched delimiter runs.
|
|
161
|
+
"""
|
|
162
|
+
if "`" not in content:
|
|
163
|
+
return []
|
|
164
|
+
|
|
165
|
+
spans: list[tuple[int, int]] = []
|
|
166
|
+
_CODE_SPAN_PARSER.inline.parse(content, _CODE_SPAN_PARSER, {_CODE_SPANS_KEY: spans}, [])
|
|
167
|
+
return spans
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
def _mask_wikilinks_in_inline_code(content: str, code_spans: list[tuple[int, int]]) -> str:
|
|
171
|
+
"""Mask only brackets in code spans, retaining all non-link source text."""
|
|
172
|
+
if not code_spans:
|
|
173
|
+
return content
|
|
174
|
+
|
|
175
|
+
masked = list(content)
|
|
176
|
+
for start, end in code_spans:
|
|
177
|
+
for position in range(start, end):
|
|
178
|
+
if masked[position] in "[]":
|
|
179
|
+
masked[position] = " "
|
|
180
|
+
|
|
181
|
+
return "".join(masked)
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
def _remove_links_to_directive_outside_inline_code(
|
|
185
|
+
content: str, code_spans: list[tuple[int, int]]
|
|
186
|
+
) -> tuple[str, bool]:
|
|
187
|
+
"""Remove a terminal directive only when MarkdownIt parsed it as non-code."""
|
|
188
|
+
directive_content = list(content)
|
|
189
|
+
for start, end in code_spans:
|
|
190
|
+
directive_content[start:end] = " " * (end - start)
|
|
191
|
+
|
|
192
|
+
match = _LINKS_TO_DIRECTIVE.search("".join(directive_content))
|
|
193
|
+
if not match:
|
|
194
|
+
return content, False
|
|
195
|
+
return content[: match.start()].rstrip(), True
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
def _relation_parsing_content(token: Token) -> tuple[str, str, list[tuple[int, int]]]:
|
|
199
|
+
"""Build source-preserving relation input from MarkdownIt's code spans."""
|
|
200
|
+
source_content = _relation_content(token)
|
|
201
|
+
code_spans = _inline_code_spans(source_content)
|
|
202
|
+
return (
|
|
203
|
+
source_content,
|
|
204
|
+
_mask_wikilinks_in_inline_code(source_content, code_spans),
|
|
205
|
+
code_spans,
|
|
206
|
+
)
|
|
207
|
+
|
|
208
|
+
|
|
130
209
|
def parse_relation_type(content: str) -> str | None:
|
|
131
210
|
"""Return the explicit relation label before the first wikilink, if any."""
|
|
132
211
|
before_link = content.partition("[[")[0].strip()
|
|
@@ -154,15 +233,17 @@ def is_explicit_relation(token: Token) -> bool:
|
|
|
154
233
|
if token.type != "inline": # pragma: no cover
|
|
155
234
|
return False
|
|
156
235
|
|
|
157
|
-
|
|
158
|
-
content = (token.tag or token.content).strip()
|
|
236
|
+
_, content, _ = _relation_parsing_content(token)
|
|
159
237
|
if "[[" not in content or "]]" not in content:
|
|
160
238
|
return False
|
|
161
239
|
return _parse_explicit_relation(content) is not None
|
|
162
240
|
|
|
163
241
|
|
|
164
|
-
def _parse_explicit_relation(
|
|
242
|
+
def _parse_explicit_relation(
|
|
243
|
+
content: str, source_content: str | None = None
|
|
244
|
+
) -> Dict[str, Any] | None:
|
|
165
245
|
"""Parse ``type [[target]] (context)``, rejecting lines with a prose tail."""
|
|
246
|
+
source_content = source_content or content
|
|
166
247
|
rel_type = parse_relation_type(content)
|
|
167
248
|
if rel_type is None:
|
|
168
249
|
return None
|
|
@@ -172,7 +253,7 @@ def _parse_explicit_relation(content: str) -> Dict[str, Any] | None:
|
|
|
172
253
|
if start == -1 or end == -1:
|
|
173
254
|
return None
|
|
174
255
|
|
|
175
|
-
target = normalize_project_reference(
|
|
256
|
+
target = normalize_project_reference(source_content[start + 2 : end].strip())
|
|
176
257
|
if not target:
|
|
177
258
|
return None
|
|
178
259
|
|
|
@@ -189,7 +270,8 @@ def _parse_explicit_relation(content: str) -> Dict[str, Any] | None:
|
|
|
189
270
|
if after:
|
|
190
271
|
if not _is_single_parenthesized(after):
|
|
191
272
|
return None
|
|
192
|
-
|
|
273
|
+
source_after = source_content[end + 2 :].strip()
|
|
274
|
+
context = source_after[1:-1].strip() or None
|
|
193
275
|
|
|
194
276
|
return {"type": rel_type, "target": target, "context": context}
|
|
195
277
|
|
|
@@ -217,13 +299,23 @@ def _is_single_parenthesized(text: str) -> bool:
|
|
|
217
299
|
|
|
218
300
|
def parse_relation(token: Token) -> Dict[str, Any] | None:
|
|
219
301
|
"""Extract relation parts from token."""
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
302
|
+
source_content, content, _ = _relation_parsing_content(token)
|
|
303
|
+
return _parse_explicit_relation(content, source_content)
|
|
304
|
+
|
|
223
305
|
|
|
306
|
+
def _is_escaped(content: str, position: int) -> bool:
|
|
307
|
+
"""Whether the character at ``position`` is escaped by an odd slash run."""
|
|
308
|
+
slash_count = 0
|
|
309
|
+
position -= 1
|
|
310
|
+
while position >= 0 and content[position] == "\\":
|
|
311
|
+
slash_count += 1
|
|
312
|
+
position -= 1
|
|
313
|
+
return slash_count % 2 == 1
|
|
224
314
|
|
|
225
|
-
|
|
226
|
-
|
|
315
|
+
|
|
316
|
+
def parse_inline_relations(content: str, source_content: str | None = None) -> List[Dict[str, Any]]:
|
|
317
|
+
"""Find wiki-style links, extracting targets from the original source."""
|
|
318
|
+
source_content = content if source_content is None else source_content
|
|
227
319
|
relations = []
|
|
228
320
|
start = 0
|
|
229
321
|
|
|
@@ -232,6 +324,9 @@ def parse_inline_relations(content: str) -> List[Dict[str, Any]]:
|
|
|
232
324
|
start = content.find("[[", start)
|
|
233
325
|
if start == -1: # pragma: no cover
|
|
234
326
|
break
|
|
327
|
+
if _is_escaped(content, start):
|
|
328
|
+
start += 2
|
|
329
|
+
continue
|
|
235
330
|
|
|
236
331
|
# Find matching ]]
|
|
237
332
|
depth = 1
|
|
@@ -239,10 +334,10 @@ def parse_inline_relations(content: str) -> List[Dict[str, Any]]:
|
|
|
239
334
|
end = -1
|
|
240
335
|
|
|
241
336
|
while pos < len(content):
|
|
242
|
-
if content[pos : pos + 2] == "[[":
|
|
337
|
+
if content[pos : pos + 2] == "[[" and not _is_escaped(content, pos):
|
|
243
338
|
depth += 1
|
|
244
339
|
pos += 2
|
|
245
|
-
elif content[pos : pos + 2] == "]]":
|
|
340
|
+
elif content[pos : pos + 2] == "]]" and not _is_escaped(content, pos):
|
|
246
341
|
depth -= 1
|
|
247
342
|
if depth == 0:
|
|
248
343
|
end = pos
|
|
@@ -255,7 +350,7 @@ def parse_inline_relations(content: str) -> List[Dict[str, Any]]:
|
|
|
255
350
|
# No matching ]] found
|
|
256
351
|
break
|
|
257
352
|
|
|
258
|
-
target = normalize_project_reference(
|
|
353
|
+
target = normalize_project_reference(source_content[start + 2 : end].strip())
|
|
259
354
|
if target:
|
|
260
355
|
relations.append({"type": "links_to", "target": target, "context": None})
|
|
261
356
|
|
|
@@ -336,21 +431,27 @@ def relation_plugin(md: MarkdownIt) -> None:
|
|
|
336
431
|
|
|
337
432
|
# Only process inline tokens
|
|
338
433
|
if token.type == "inline":
|
|
339
|
-
|
|
340
|
-
|
|
434
|
+
source_content = _relation_content(token)
|
|
435
|
+
if "[[" not in source_content:
|
|
436
|
+
continue
|
|
437
|
+
|
|
438
|
+
code_spans = _inline_code_spans(source_content)
|
|
439
|
+
relation_content = _mask_wikilinks_in_inline_code(source_content, code_spans)
|
|
440
|
+
content_without_directive, has_directive = (
|
|
441
|
+
_remove_links_to_directive_outside_inline_code(relation_content, code_spans)
|
|
442
|
+
)
|
|
341
443
|
|
|
342
444
|
# Check for explicit relations in list items
|
|
343
|
-
if in_list_item and not has_directive
|
|
344
|
-
rel =
|
|
445
|
+
if in_list_item and not has_directive:
|
|
446
|
+
rel = _parse_explicit_relation(relation_content, source_content)
|
|
345
447
|
if rel:
|
|
346
448
|
token.meta["relations"] = [rel]
|
|
449
|
+
continue
|
|
347
450
|
|
|
348
451
|
# Always check for inline links in any text
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
if rels:
|
|
353
|
-
token.meta["relations"] = token.meta.get("relations", []) + rels
|
|
452
|
+
rels = parse_inline_relations(content_without_directive, source_content)
|
|
453
|
+
if rels:
|
|
454
|
+
token.meta["relations"] = token.meta.get("relations", []) + rels
|
|
354
455
|
|
|
355
456
|
# Add the rule after inline processing
|
|
356
457
|
md.core.ruler.after("inline", "relations", relation_rule)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: basic-memory
|
|
3
|
-
Version: 0.23.3.
|
|
3
|
+
Version: 0.23.3.dev3
|
|
4
4
|
Summary: Local-first knowledge management combining Zettelkasten with knowledge graphs
|
|
5
5
|
Project-URL: Homepage, https://github.com/basicmachines-co/basic-memory
|
|
6
6
|
Project-URL: Repository, https://github.com/basicmachines-co/basic-memory
|
|
@@ -162,7 +162,7 @@ basic_memory/indexing/accepted_note_enqueue_runner.py,sha256=v0BQTdKFOnhwrvls4QB
|
|
|
162
162
|
basic_memory/indexing/accepted_note_mutation_runner.py,sha256=BTaMDcE2GpF4S5uhF2tHzxFbBOy1fOgUVjmB2_Wyj0M,47564
|
|
163
163
|
basic_memory/indexing/accepted_note_search.py,sha256=fNcuxOKJ_zVM6FVlZQ8-OGjG3E3NXGJwkTuvO8aF0PU,4748
|
|
164
164
|
basic_memory/indexing/accepted_note_write_runner.py,sha256=ZvQlX47C8oD-VTCBWSEDCzTE3x938IPetZQp48_H_PM,25759
|
|
165
|
-
basic_memory/indexing/batch_indexer.py,sha256=
|
|
165
|
+
basic_memory/indexing/batch_indexer.py,sha256=KL0jRk9zJKmyKsWtE23oRZox5Y-XISLbSOeeXZOvhfI,38361
|
|
166
166
|
basic_memory/indexing/batching.py,sha256=-gOgdw-hu7crfvM6TaAvykmViyQLjZHEVtRDnUD3SsU,2297
|
|
167
167
|
basic_memory/indexing/change_detector.py,sha256=h198EwavsKkAA8FS2mR3fqAwZrfWWCBk5Zyxj7R5LqU,7392
|
|
168
168
|
basic_memory/indexing/change_planning.py,sha256=kgnn3RWdkthkempzT-a5_hqcvOJHqZAhRO48dXZchJk,6896
|
|
@@ -174,7 +174,7 @@ basic_memory/indexing/file_index_checking.py,sha256=pDnx_ELXEUeMx3HKiTukf6TgcCNg
|
|
|
174
174
|
basic_memory/indexing/file_index_planning.py,sha256=kbLmX0Ri5FjG_oa1xEFf5XIMx4u1v-tGFom56kVUSvg,6604
|
|
175
175
|
basic_memory/indexing/file_indexer.py,sha256=BXh5cMBvB_loj3aW4Ag4hIqy7VX_pWOZWuq2k420H20,9077
|
|
176
176
|
basic_memory/indexing/forward_reference_resolution.py,sha256=be7z8CJEbwMVb2kOgS2egmg7TCZBiM7GjFPZQb2B3dY,11790
|
|
177
|
-
basic_memory/indexing/index_batch_runtime.py,sha256=
|
|
177
|
+
basic_memory/indexing/index_batch_runtime.py,sha256=wp4BUZGmFvRqkr3Azm-8p5FT6fx374g5oY3aJvxppxU,7784
|
|
178
178
|
basic_memory/indexing/index_file_runner.py,sha256=mu--rGqBKnWfn4N9X2HOdFJThlmJ_xdAs3wakTEh6kc,10838
|
|
179
179
|
basic_memory/indexing/index_file_runtime.py,sha256=5-XiDINhIM1SJiG2BmZtji9ElfQmLsaRCBZlBE3mUTs,5143
|
|
180
180
|
basic_memory/indexing/input_file_adaptation.py,sha256=qoBrqt4GD_W5F0nt3af1aLeSLRnM-2AUiJlhLKH8g5M,1649
|
|
@@ -206,7 +206,7 @@ basic_memory/man/bm.1,sha256=iQhnHzJHSN3WRdMIphv22AnWTYR2SErzeKwCqQJ3LzQ,3406
|
|
|
206
206
|
basic_memory/markdown/__init__.py,sha256=DdzioCWtDnKaq05BHYLgL_78FawEHLpLXnp-kPSVfIc,501
|
|
207
207
|
basic_memory/markdown/entity_parser.py,sha256=7RUL7QXOQc00ez7OFOJB6kvsD8yY6K_yVD4VGSHOPxc,12629
|
|
208
208
|
basic_memory/markdown/markdown_processor.py,sha256=YK8KF8NY0N9nQM3I_8Pcxybf5SPOPnIL5kzmFBFBlx0,7429
|
|
209
|
-
basic_memory/markdown/plugins.py,sha256=
|
|
209
|
+
basic_memory/markdown/plugins.py,sha256=US8WhuZVfElSPGlSjP8_8C1J_dvasc6EjZJAF7-QvZ8,16464
|
|
210
210
|
basic_memory/markdown/schemas.py,sha256=IHi4sm40ew4zNjb359imwiPJXGO6cIni_1f3YNVyZPs,2798
|
|
211
211
|
basic_memory/markdown/utils.py,sha256=EP8P8uDNrhcnvpgc_iaczIQK3r9Z6k1MHMKCcZvTzm0,4122
|
|
212
212
|
basic_memory/mcp/__init__.py,sha256=dsDOhKqjYeIbCULbHIxfcItTbqudEuEg1Np86eq0GEQ,35
|
|
@@ -390,8 +390,8 @@ basic_memory/services/search_service.py,sha256=8A1vXo5IIpKXL2gxEsCEP_tcKyRcnz4R5
|
|
|
390
390
|
basic_memory/services/service.py,sha256=V-d_8gOV07zGIQDpL-Ksqs3ZN9l3qf3HZOK1f_YNTag,336
|
|
391
391
|
basic_memory/templates/prompts/continue_conversation.hbs,sha256=trrDHSXA5S0JCbInMoUJL04xvCGRB_ku1RHNQHtl6ZI,3076
|
|
392
392
|
basic_memory/templates/prompts/search.hbs,sha256=H1cCIsHKp4VC1GrH2KeUB8pGe5vXFPqb2VPotypmeCA,3098
|
|
393
|
-
basic_memory-0.23.3.
|
|
394
|
-
basic_memory-0.23.3.
|
|
395
|
-
basic_memory-0.23.3.
|
|
396
|
-
basic_memory-0.23.3.
|
|
397
|
-
basic_memory-0.23.3.
|
|
393
|
+
basic_memory-0.23.3.dev3.dist-info/METADATA,sha256=qz-h94DI89jpFRsu-PBA9Wc5iDAGRfetgfPRAIxGly8,26812
|
|
394
|
+
basic_memory-0.23.3.dev3.dist-info/WHEEL,sha256=zOwg4jB6zX2kU910N-cMawjivD6tO8NEWvE12je1bVk,87
|
|
395
|
+
basic_memory-0.23.3.dev3.dist-info/entry_points.txt,sha256=wvE2mRF6-Pg4weIYcfQ-86NOLZD4WJg7F7TIsRVFLb8,90
|
|
396
|
+
basic_memory-0.23.3.dev3.dist-info/licenses/LICENSE,sha256=hIahDEOTzuHCU5J2nd07LWwkLW7Hko4UFO__ffsvB-8,34523
|
|
397
|
+
basic_memory-0.23.3.dev3.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|