技能创建器
skill-creator
创建、改进和评估自定义技能,把专业流程转化为可重复使用的 AI 能力。
embeddings-search【数据与研究】Build, query, maintain, and troubleshoot txtai embeddings databases for semantic, SQL, hybrid, graph, object, and subindex search.
独立 GitHub 快照 · 自动分类 · 以原作者文档为准
Use this sub-skill when the task is to build, update, persist, query, or debug a txtai Embeddings database. txtai search combines dense vector indexes, optional sparse scoring, optional graph storage, and optional relational content storage behind the Embeddings API.
(id, data), (id, data, tags), or dictionary rows.content=True dictionary/SQL results.similarity, batchsearch, SQL similar(...), bind parameters, filters, and aggregations.index, upsert, delete, reindex, save, load, exists, count, and close.RAG, LLM, or Agent orchestration, use agents-and-llm-orchestration.Workflow task chains, use pipelines-and-workflows.Application, FastAPI, OpenAI-compatible routes, or deployment config, use api-and-deployment.python scripts/semantic_search_smoke.py --help to see a safe helper adapted from txtai's similarity demo.python scripts/semantic_search_smoke.py --run --sql for a local deterministic dry-run that avoids model downloads by using an explicit external vector transform.Embeddings() or Embeddings(path="...") for default dense semantic search when model downloads are acceptable.Embeddings(method="external", transform=...) or Embeddings({"method": "external"}) when vectors are supplied by local code or precomputed arrays.content=True before indexing when the task needs stored text, metadata fields, SQL queries, object retrieval, or reindex from stored content.(id, score) are enough and metadata retrieval is unnecessary.upsert for incremental insert/update and index only when replacing the whole index is intended.reindex only after content storage exists; it rebuilds vectors/indexes from stored content and avoids returning to raw source rows.close() when database, graph, scoring, or ANN resources should be released promptly.from txtai import Embeddings
rows = [
("a", {"text": "Maine man wins lottery ticket", "topic": "lucky"}, None),
("b", {"text": "Canada ice shelf collapsed", "topic": "climate"}, None),
]
with Embeddings(content=True) as embeddings:
embeddings.index(rows)
print(embeddings.search("feel good story", 3))
print(embeddings.search(
"select id, text, score from txtai where similar(:q, 10) and topic = :topic",
parameters={"q": "lucky", "topic": "lucky"},
))
# Tuple-only result mode: no SQL, no stored metadata.
embeddings = Embeddings()
embeddings.index(["Correct", "Not what we hoped"])
assert embeddings.search("positive", 1)[0][0] == 0
Embeddings(path=...), call index(rows), then search(query, limit) or similarity(query, candidates).Embeddings(content=True), index dictionaries with a text field plus metadata, and query with SQL filters.similar('query', candidates) with a candidate count larger than the final limit when filters may discard matches.parameters={...} for similar(:q) and field filters like topic = :topic instead of interpolating user text.Embeddings(content=True, objects=True) and index dictionaries with text plus object bytes or encoder-backed objects.hybrid=True, keyword=True, or sparse=... when sparse keyword/vector evidence should combine with dense search.graph=True or a graph config, then run graph-enabled searches or openCypher-style graph queries.defaults=False and indexes={...} when different fields, models, or sparse/dense strategies need separate named indexes.save(path) after building and Embeddings().load(path) before querying; compressed and cloud-backed saves are advanced variants.search returns [(id, score), ...] and ids map to input ids or generated ids.search returns dictionaries keyed by selected SQL/query columns, usually including id, text, score, and metadata.similarity(query, data) always compares a query against an in-memory candidate list and returns sorted (candidate_index, score) tuples.batchsearch returns one result list per query and accepts per-query parameter dictionaries.graph=True.python - <<'PY'\nfrom txtai import Embeddings\nprint(Embeddings)\nPYpython scripts/semantic_search_smoke.py --help.python scripts/semantic_search_smoke.py --run --sql.content=True before index or upsert.Embeddings().exists(path).content=True enabled before indexing, not after?upsert or delete calls?similar(...) candidate counts high enough for downstream filters?close() called or a context manager used when long-lived resources are no longer needed?