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

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