embeddings-search
Build, query, maintain, and troubleshoot txtai embeddings databases for semantic, SQL, hybrid, graph, object, and subindex search.
- License 许可
- Apache-2.0
- 最近更新
- 2026-09-03
- Stars
- ★ 351
- Forks
- 27
01 前言 Front Matter
- name
- embeddings-search
- license
- Apache 2.0
- metadata
- { "disco-role": "operating" }
- description
- Build, query, maintain, and troubleshoot txtai embeddings databases for semantic, SQL, hybrid, graph, object, and subindex search.
- disable-model-invocation
- true
02 资源文件 4
- 参考文档references/api-reference.md8.6 KB
- 参考文档references/query-and-indexing.md11.4 KB
- 参考文档references/troubleshooting.md11.8 KB
- 脚本scripts/semantic_search_smoke.py7.5 KB
03 SKILL.md 正文
Embeddings Search
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.
Use This For
- Building an index from raw text,
(id, data),(id, data, tags), or dictionary rows. - Choosing between tuple-only vector results and
content=Truedictionary/SQL results. - Running semantic search,
similarity,batchsearch, SQLsimilar(...), bind parameters, filters, and aggregations. - Maintaining indexes with
index,upsert,delete,reindex,save,load,exists,count, andclose. - Storing metadata, dynamic columns, nested JSON, binary objects, custom SQL functions, and expressions.
- Configuring hybrid sparse+dense search, graph search, subindexes, ANN backends, and database backends.
Route Elsewhere
- For RAG answers, LLM prompting,
RAG,LLM, orAgentorchestration, use agents-and-llm-orchestration. - For document extraction, chunking, pipeline preprocessing, or deterministic
Workflowtask chains, use pipelines-and-workflows. - For serving an index through
Application, FastAPI, OpenAI-compatible routes, or deployment config, use api-and-deployment.
Start Here
- Read references/api-reference.md for constructor options, method signatures, row formats, result shapes, and lifecycle calls.
- Read references/query-and-indexing.md for concrete semantic, SQL, hybrid, graph, object, subindex, and save/load recipes.
- Read references/troubleshooting.md before changing configuration, optional backends, persistence paths, or SQL queries.
- Run
python scripts/semantic_search_smoke.py --helpto see a safe helper adapted from txtai's similarity demo. - Run
python scripts/semantic_search_smoke.py --run --sqlfor a local deterministic dry-run that avoids model downloads by using an explicit external vector transform.
Core Decisions
- Use
Embeddings()orEmbeddings(path="...")for default dense semantic search when model downloads are acceptable. - Use
Embeddings(method="external", transform=...)orEmbeddings({"method": "external"})when vectors are supplied by local code or precomputed arrays. - Set
content=Truebefore indexing when the task needs stored text, metadata fields, SQL queries, object retrieval, orreindexfrom stored content. - Leave content disabled only when tuple results
(id, score)are enough and metadata retrieval is unnecessary. - Use explicit ids for records that will later be updated or deleted; auto-generated ids require a prior search to discover target ids.
- Use
upsertfor incremental insert/update andindexonly when replacing the whole index is intended. - Use
reindexonly after content storage exists; it rebuilds vectors/indexes from stored content and avoids returning to raw source rows. - Use a context manager or call
close()when database, graph, scoring, or ANN resources should be released promptly.
Minimal Patterns
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
Common Workflows
- Quick semantic search: create
Embeddings(path=...), callindex(rows), thensearch(query, limit)orsimilarity(query, candidates). - Metadata filters: create
Embeddings(content=True), index dictionaries with atextfield plus metadata, and query with SQL filters. - SQL candidate tuning: use
similar('query', candidates)with a candidate count larger than the finallimitwhen filters may discard matches. - Safe bind parameters: pass
parameters={...}forsimilar(:q)and field filters liketopic = :topicinstead of interpolating user text. - Object storage: create
Embeddings(content=True, objects=True)and index dictionaries withtextplusobjectbytes or encoder-backed objects. - Hybrid search: use
hybrid=True,keyword=True, orsparse=...when sparse keyword/vector evidence should combine with dense search. - Graph search: use
graph=Trueor a graph config, then run graph-enabled searches or openCypher-style graph queries. - Subindexes: use
defaults=Falseandindexes={...}when different fields, models, or sparse/dense strategies need separate named indexes. - Persistence: call
save(path)after building andEmbeddings().load(path)before querying; compressed and cloud-backed saves are advanced variants.
Result Shapes
- Without content storage,
searchreturns[(id, score), ...]and ids map to input ids or generated ids. - With content storage,
searchreturns dictionaries keyed by selected SQL/query columns, usually includingid,text,score, and metadata. similarity(query, data)always compares a query against an in-memory candidate list and returns sorted(candidate_index, score)tuples.batchsearchreturns one result list per query and accepts per-query parameter dictionaries.- Graph searches may return graph objects or graph-backed query rows depending on query and
graph=True.
Validation Checklist
- Import check:
python - <<'PY'\nfrom txtai import Embeddings\nprint(Embeddings)\nPY - Script check:
python scripts/semantic_search_smoke.py --help. - No-download dry-run:
python scripts/semantic_search_smoke.py --run --sql. - For SQL tasks, assert the embeddings object was created with
content=Truebeforeindexorupsert. - For save/load tasks, assert the saved path contains a txtai config and component directories or load via
Embeddings().exists(path).
Troubleshooting First Questions
- Is
content=Trueenabled before indexing, not after? - Are ids stable and explicit for later
upsertordeletecalls? - Is the query natural language, SQL, or graph syntax, and does the configured index support that mode?
- Are optional ANN, database, graph, sparse, or vector backend packages installed for the selected config?
- Is a model path local/available, or will the environment need network/cache access to download it?
- Are SQL
similar(...)candidate counts high enough for downstream filters? - Are hybrid weights and sparse/dense score normalization intentionally configured?
- Was
close()called or a context manager used when long-lived resources are no longer needed?
04 同仓库更多 Skills
passnet-triton-opt
Make a single PassNet Triton kernel fast AND numerically faithful: performance model (when a replacement can win at all), block/grid/warp tuning, autotune policy, launch overhead, and per-op numeric recipes to pass the dtype baseline tolerances. Use when a pass matches and is correct but speedup below expected, or when correctness fails by small numeric margins.
passnet-solve
END-TO-END playbook for solving one PassNet sample: analyze the computation graphs, decide the optimization strategy (what to fuse, what to replace, what to leave alone), drive the iteration loop, and maximize the sample score. This is the ENTRY skill — invoke it first for any PassNet optimization task; it tells you when to use passnet-pattern-fusion, passnet-triton-opt and passnet-feedback.
passnet-skill
PassNet GPU kernel optimization via compiler passes. Design and implement Triton-based optimization passes, create pass files under ./pass_dir/, self-evaluate with pass_evaluator, and iterate to maximize GPU speedup.
passnet-pattern-fusion
Author PassNet pass files: write patterns that actually MATCH the FX graph, pick fusion regions (which ops to absorb into one Triton kernel), and structure multi-pass submissions with the mandatory shared-dispatch architecture. Use when creating or fixing pattern()/replacement_args()/replacement_func() files, when a pass "failed to match", or when deciding how to fuse multiple kernels/ops.
passnet-orchestrate
Round/batch planning and decision support for PassNet graph optimization. Use for multi-sample triage, worker allocation, eval-budget policy, and post-eval keep/revert decisions. For solving one concrete sample end to end, use passnet-solve as the entry skill; consult this skill only when you need broader planning or a specific decision gate.
passnet-feedback
Fast, deterministic feedback for PassNet work: pre-flight pattern/match verification WITHOUT burning a GPU evaluation, per-node bottleneck analysis of a sample's graphs, and eval-log parsing into per-variant status + estimated score + failure classification. Use BEFORE every GPU evaluation (check_pattern), at the START of a sample (analyze_graph), and AFTER every evaluation (parse_eval_log).