MCPcopy Create free account
hub / github.com/OpenRaiser/PaperFlow / embed_nodes_for_user

Function embed_nodes_for_user

skills/wiki-store/scripts/wiki_db.py:352–403  ·  view source on GitHub ↗

Embed wiki nodes with the configured embedding provider.

(
    user_id: str,
    node_ids: Optional[List[str]] = None,
    *,
    force: bool = False,
    limit: int = 500,
)

Source from the content-addressed store, hash-verified

350 "SELECT * FROM wiki_nodes WHERE user_id = ? AND node_id = ?",
351 (user_id, node_id),
352 ).fetchone()
353 conn.close()
354 node = _row_to_node(row)
355 if write_mirror:
356 write_node_mirror(node)
357 return node
358
359
360def embed_nodes_for_user(
361 user_id: str,
362 node_ids: Optional[List[str]] = None,
363 *,
364 force: bool = False,
365 limit: int = 500,
366) -> Dict[str, Any]:
367 """Embed wiki nodes with the configured embedding provider."""
368 init_wiki_schema()
369 from paperflow.providers import build_embedding_provider
370
371 params: List[Any] = [user_id]
372 where = "WHERE user_id = ?"
373 if node_ids:
374 placeholders = ",".join("?" for _ in node_ids)
375 where += f" AND node_id IN ({placeholders})"
376 params.extend(node_ids)
377 if not force:
378 where += " AND embedding IS NULL"
379 params.append(max(1, int(limit)))
380
381 conn = db_ops.get_connection()
382 rows = conn.execute(
383 f"""
384 SELECT * FROM wiki_nodes
385 {where}
386 ORDER BY updated_at DESC, id DESC
387 LIMIT ?
388 """,
389 params,
390 ).fetchall()
391 if not rows:
392 conn.close()
393 return {"embedded": 0, "model": None}
394
395 nodes = _rows_to_nodes(rows)
396 provider = build_embedding_provider()
397 texts = [_node_embedding_text(node) for node in nodes]
398 vectors = provider.embed_batch(texts)
399 model_name = f"{provider.name}:{provider.model}"
400 for node, vector in zip(nodes, vectors):
401 conn.execute(
402 """
403 UPDATE wiki_nodes
404 SET embedding = ?, embedding_model = ?, updated_at = ?
405 WHERE user_id = ? AND node_id = ?
406 """,

Callers

nothing calls this directly

Calls 10

build_embedding_providerFunction · 0.90
init_wiki_schemaFunction · 0.85
_rows_to_nodesFunction · 0.85
_node_embedding_textFunction · 0.85
_vector_to_blobFunction · 0.85
_nowFunction · 0.85
fetchallMethod · 0.45
executeMethod · 0.45
closeMethod · 0.45
embed_batchMethod · 0.45

Tested by

no test coverage detected