context-retrieval
安装方式
先用 Prompt 核对来源与依赖。也可下载安装包。
用 AI 助手安装
复制提示词,让助手先核对固定版本和依赖。
查看 Prompt收起 Prompt
先检查当前 Agent 是否已安装 SkillPI Skill Finder。如果尚未安装,请按官方仓库的说明安装并启用:https://github.com/Findskills/skillpi。然后使用 Skill Finder 打开此 SkillPI 详情页并定位 "context-retrieval":https://skillpi.com/zh/skills/deepskill-e5ad2b826de445435f024ff4eb411d011cc1d75acb7a70ae7a5f596597dadad3。安装前核对上游来源和版本:https://skillhub.cn/skills/user_3c6cb52e/context-retrieval。来源不一致时停止并说明差异。核对通过后,用 Skill Finder 安装目标 Skill,并报告安装路径和来源版本。
来源与配置
skillhub.cn
配置方式待核实
请查看原始来源中的适用工具、依赖和权限要求。
安装实测待补充
使用 RAG 技术从知识库中检索并合成相关信息,为空查询提供有根据的上下文。
介绍来源: third_party · user_3c6cb52e · 1.0.0 参考来源
SkillPi 解读
- 能完成的任务
- 使用RAG技术从知识库中检索和合成相关信息,以为空查询提供有根据的上下文。
- 适合谁
- 来源文档未说明。
- 输入和输出
- 来源文档未说明。
- 软件、账号及付费要求
- 来源文档未说明。
- 限制与区别
- 来源文档未说明。
- 实测状态
- 未测试
文件浏览
Frontmatter
name: 上下文检索
slug: "context-retrieval"
version: "1.0.0"
displayName: "上下文检索"
summary: "使用RAG技术从知识库中检索并合成相关信息,以为空查询提供有根据的上下文。"
description: "使用RAG技术从知识库中检索和合成相关信息,以为空查询提供有根据的上下文。"
license: MIT
metadata:
author: awesome-ai-agent-skills
version: "1.0.0"上下文检索
Context retrieval is the process of finding and assembling the most relevant pieces of information from a knowledge base to ground an AI agent's responses in factual, up-to-date data. It is the backbone of Retrieval Augmented Generation (RAG) and ensures that generated outputs are accurate and verifiable rather than hallucinated.
Workflow
-
Embed the Query: Convert the user's natural-language query into a dense vector representation using an embedding model (e.g., OpenAI
text-embedding-3-small, Cohereembed-v3, or an open-source model likebge-large). The embedding captures the semantic meaning of the query so it can be compared against stored documents. -
Search the Vector Store: Send the query embedding to a vector database (Pinecone, Weaviate, Qdrant, Chroma, etc.) and perform an approximate nearest-neighbor (ANN) search. Request the top-k candidate chunks, typically k = 10–20 to give the reranker enough material to work with.
-
Rerank the Results: Pass the candidate chunks through a cross-encoder reranker (e.g., Cohere Rerank,
bge-reranker-large, or a ColBERT model). The reranker scores each chunk against the original query with full attention, producing much more accurate relevance scores than cosine similarity alone. Keep the top-n results (typically n = 3–5). -
Assemble the Context Window: Concatenate the selected chunks into a single context block, ordered by relevance score descending. Prepend source metadata (file path, URL, page number) to each chunk so the agent can cite its sources. Ensure the total token count fits the model's budget for the context section of the prompt.
-
Generate the Response: Feed the assembled context into the LLM prompt alongside the original query and a system instruction that tells the model to answer only from the provided context. This grounds the response in retrieved facts and reduces hallucination.
-
Validate and Cite: After generation, verify that the answer references information actually present in the retrieved chunks. Attach inline citations or a references section so the user can trace each claim back to a source document.
Key Concepts
- Semantic Search: Uses vector embeddings to find documents by meaning rather than exact keyword match. Excels at paraphrasing and synonym handling but can miss precise technical terms.
- Keyword Search (BM25): Traditional term-frequency search that excels at exact matches and rare terms. Fast and interpretable but blind to synonyms.
- Hybrid Search: Combines semantic and keyword search (e.g., weighted fusion of BM25 + cosine similarity scores) to get the best of both worlds. Most production RAG systems use hybrid retrieval.
- Chunking Strategies: Documents must be split into chunks before indexing. Common strategies include fixed-size token windows (256–512 tokens with 50-token overlap), sentence-boundary splitting, and recursive character splitting. Smaller chunks improve precision; larger chunks preserve more context.
- Embedding Models: The choice of embedding model affects retrieval quality. Larger models (1024+ dimensions) capture more nuance but cost more to store and query. Always benchmark on your domain before choosing.
Usage
To use this skill, you need a pre-indexed knowledge base with document embeddings stored in a vector database. Provide a natural-language query as input. The skill returns the retrieved context block ready for prompt assembly, along with source metadata for citation.
Examples
Example 1: Retrieving Codebase Context for a Code Question
Query: "How does the authentication middleware validate JWT tokens?"
Retrieved Chunks (after reranking):
| Rank | Source | Score | Snippet |
|---|---|---|---|
| 1 | src/middleware/auth.ts:14-38 |
0.94 | export function validateToken(req, res, next) { const token = req.headers.authorization?.split(' ')[1]; if (!token) return res.status(401).json({ error: 'Missing token' }); try { const decoded = jwt.verify(token, process.env.JWT_SECRET); req.user = decoded; next(); } catch (e) { return res.status(403).json({ error: 'Invalid token' }); } } |
| 2 | docs/auth-flow.md:8-22 |
0.87 | "The JWT is signed with HS256 using the JWT_SECRET env var. Tokens expire after 24 hours. The middleware extracts the token from the Authorization header, verifies the signature, and attaches the decoded payload to req.user." |
| 3 | tests/auth.test.ts:5-19 |
0.72 | Test cases covering valid token, expired token, and malformed token scenarios. |
Assembled Prompt:
Answer the following question using ONLY the provided context. Cite file paths.
Context:
[1] src/middleware/auth.ts:14-38 — export function validateToken(req, res, next) { ... }
[2] docs/auth-flow.md:8-22 — The JWT is signed with HS256 using the JWT_SECRET env var...
[3] tests/auth.test.ts:5-19 — Test cases covering valid token, expired token...
Question: How does the authentication middleware validate JWT tokens?
Example 2: Retrieving Product Docs for a Support Question
Query: "How do I reset my password if I no longer have access to my email?"
Retrieved Chunks:
help/account-recovery.md(score 0.91) — "If you cannot access your registered email, navigate to Settings > Account > Identity Verification. You will be asked to verify your identity using your phone number or a government-issued ID. Once verified, you can set a new email and reset your password."help/password-reset.md(score 0.85) — "To reset your password, click 'Forgot Password' on the login page. A reset link will be sent to your registered email address. The link expires after 1 hour."
Generated Answer: "Since you no longer have access to your email, use the identity verification flow: go to Settings > Account > Identity Verification, verify via phone number or government ID, update your email address, then reset your password from the login page. [Sources: help/account-recovery.md, help/password-reset.md]"
Best Practices
- Use hybrid retrieval in production — combining BM25 keyword search with semantic vector search consistently outperforms either approach alone.
- Always rerank — a cross-encoder reranker on the top-20 results dramatically improves precision compared to relying on embedding cosine similarity alone.
- Chunk with overlap — use 10–20% token overlap between adjacent chunks to prevent splitting critical information across chunk boundaries.
- Include metadata — store file paths, section headings, timestamps, and authors alongside embeddings so retrieved context is traceable and citable.
- Tune top-k empirically — retrieve more candidates than you need (k = 15–20), then let the reranker narrow to the best 3–5. This balances recall and precision.
- Benchmark regularly — measure retrieval quality with metrics like Recall@k, MRR, and NDCG on a labeled evaluation set from your domain.
Edge Cases
- No relevant results found: When the top retrieval score is below a confidence threshold (e.g., < 0.5), the agent should acknowledge that it does not have enough information rather than fabricating an answer.
- Contradictory sources: If retrieved chunks contain conflicting information, surface both perspectives and note the discrepancy rather than silently picking one.
- Stale or outdated content: Documents indexed months ago may be outdated. Include timestamps in metadata and prefer more recent chunks when scores are close.
- Very short or very long queries: Single-word queries may produce noisy results — consider query expansion. Very long queries may benefit from decomposition into sub-queries with results merged.
- Multi-language knowledge bases: Ensure the embedding model supports the languages present in the corpus, or use a translation step before embedding.
当前收录版本
1.0.0
安全与评测信息
质量评测
满分100 · 来自 SkillPi LAB 实验室的评测报告。
亮点
- Skill 针对 RAG 上下文检索这一 AI 开发中的高频刚需场景,具有明确的实用价值
- 适用于代码库检索、产品文档支持等广泛场景,能有效提升 AI 应用的准确性和可信度
亮点
- description 明确描述了使用 RAG 技术从知识库中检索信息的功能
- 触发词清晰,边界明确,覆盖多种变体,用户能准确理解 Skill 的用途
亮点
- 文档结构完整,包含 Workflow、Key Concepts、Usage、Examples、Best Practices、Edge Cases 等清晰章节
- 步骤划分明确,有端到端示例,frontmatter 完整,单文件未超过 500 行
亮点
- 详细描述了 RAG 流程的每一步,工具来源明确(如 OpenAI、Cohere、Pinecone 等)
- 参数建议合理,覆盖了主要异常情况(如无相关结果、矛盾来源等),并提供了最佳实践和边缘案例处理
取前四项原始分值的算术平均,四舍五入取整。可通过收录报告核对各项评分与说明,运行记录需单独查证。
正文静态检测
100 / 100 · skillpi-20261123-no-r3-v1
正文未命中当前规则。
分数仅反映正文中的规则命中,供使用前参考。附件与运行行为不在此评分范围内。
权限与使用前检查
根据当前主文档自动整理,命中内容可能是示例或防护说明;不是实际权限声明,也未覆盖附件、外部依赖或运行行为。
未从主文档识别到上述常见操作,不能据此判断无需权限或没有风险。
安全评级与访问范围
safe · 静态证据核验,不代表运行安全保证。
来源文档未说明。
使用前请由宿主核对并授权实际文件读写、外部服务和联网目的地;本站的核验不会授予任何运行权限。
用户讨论
还没有已核实的点评。