Agent skill
semantic-search
Automatically search indexed code when user asks questions about the codebase. Detects code-related queries and uses semantic memory to find relevant files. Activates for questions like "how does X work", "where is Y", "show me Z implementation".
Install this agent skill to your Project
npx add-skill https://github.com/squirrelsoft-dev/infinite-memory/tree/main/skills/semantic-search
SKILL.md
Infinite Memory Semantic Search Skill
Auto-search code using semantic memory when user asks codebase questions.
Activation Logic
This skill activates when ALL of these conditions are met:
-
User question contains code-related keywords:
- Questions: "how does", "where is", "show me", "find", "what is", "explain"
- Code concepts: "function", "class", "API", "route", "model", "database", "authentication", "configuration", etc.
- Patterns: "decorator", "middleware", "handler", "service", "controller"
-
Current project appears to be indexed:
- Check for Pixeltable database in ~/.pixeltable/
- Or attempt a test
query_memorycall - If not indexed, do not activate (let setup-assistant skill handle it)
-
Question is about THIS codebase:
- Not about external libraries ("how does React work?")
- Not general programming questions ("how do I write a loop?")
- About the current project's implementation
Execution Steps
1. Detect Query Intent
Extract the search query from user's natural language question:
Examples:
- "How does authentication work?" → query: "authentication work"
- "Where is the User model defined?" → query: "User model definition"
- "Show me error handling" → query: "error handling"
- "Find all API endpoints" → query: "API endpoints"
- "How is the database connection configured?" → query: "database connection configuration"
2. Call query_memory MCP Tool
Adjust parameters based on query type:
Specific queries (class names, function names):
query_memory(
query="UserModel class definition",
max_results=5,
similarity_threshold=0.8 # Higher threshold for precision
)
Conceptual queries (how does X work):
query_memory(
query="authentication work flow",
max_results=10,
similarity_threshold=0.7 # Normal threshold
)
Exploratory queries (find all X, show me Y):
query_memory(
query="API endpoints routes",
max_results=15,
similarity_threshold=0.6 # Lower threshold, more results
)
3. Format Results Adaptively
Specific Queries (user looking for exact thing):
- Show detailed code snippets
- Include function signatures
- Show context (surrounding code)
- Limit to top 3-5 most relevant
Conceptual Queries (user wants to understand):
- Show file paths with brief descriptions
- Explain relationships between files
- Group related results
- Can show more results (5-10)
Broad Queries (exploration/discovery):
- List file paths with one-line descriptions
- Categorize by type (models, routes, tests, etc.)
- Show more results (10-15)
- Offer to dive deeper into specific areas
4. Answer User's Question
Don't just dump search results - use them to answer the question:
Good Answer Pattern:
[Direct answer to user's question]
[Explanation based on retrieved code]
[Reference specific files with similarity scores as percentages]
[Offer to explain further or dive deeper]
Example:
User: "How does authentication work?"
Response:
Authentication in this project uses JWT tokens:
1. **Login Flow** (auth/login.py, 92% match):
- User submits credentials to /api/login
- Validates against database
- Generates JWT token with user ID and expiration
- Returns token in HTTP-only cookie
2. **Request Authentication** (middleware/auth.py, 89% match):
- Middleware intercepts protected routes
- Extracts JWT from cookie
- Verifies signature and expiration
- Adds user object to request context
3. **Session Management** (auth/session.py, 85% match):
- Stores active sessions in Redis
- Implements token refresh mechanism
- 1-hour token expiry, 7-day refresh window
The main entry point is the authenticate_request() middleware function
that runs on every protected route.
Would you like me to explain any of these components in more detail?
Anti-Patterns (When NOT to Activate)
DO NOT activate for:
❌ General programming questions:
- "How do I write a for loop in Python?"
- "What's the difference between async and sync?"
- "How does recursion work?"
❌ External library questions:
- "How does React's useState hook work?"
- "How do I use FastAPI's dependency injection?"
- "What are Django's ORM features?"
❌ Non-code questions:
- "What should we implement next?"
- "Is this architecture scalable?"
- "Should we use microservices?"
❌ Project is not indexed:
- Let the
setup-assistantskill handle this case - Don't activate and then fail - poor UX
Fallback Behavior
If No Results Found (total_results: 0)
Inform user and suggest alternatives:
I couldn't find exact matches for "[query]" in the indexed code.
This could mean:
- The feature uses different terminology
- The code hasn't been indexed yet (run /status to check)
- Try broader search terms
Would you like me to:
- Search for related concepts? (suggest alternative query)
- Check indexing status?
- Use traditional grep search instead?
If Partial Results (1-2 results with low scores <0.75)
I found some potentially related code:
[Show results with caveat]
These matches have lower confidence scores. The feature might use
different terminology, or these could be tangentially related.
Would you like me to:
- Try a broader search?
- Search for alternative terms?
Similarity Score Guidelines
When presenting scores to users, use percentages and context:
- 90-100%: "exact match" or "highly relevant"
- 80-89%: "strong match" or "very relevant"
- 70-79%: "relevant match" or "related"
- 60-69%: "possibly related" (use cautiously)
- <60%: Generally don't show (unless exploratory query with no better results)
Integration with Other Features
Work seamlessly with:
/searchcommand: User's explicit search takes precedencesetup-assistantskill: If project not indexed, defer to setup- Manual grep/read: Combine semantic search with traditional tools when needed
Performance Considerations
- Keep searches fast: <200ms for most queries
- Don't overwhelm user with too many results
- Cache recent queries if possible (future optimization)
- Bail out early if project clearly not indexed
Example Activation Scenarios
✅ Should Activate
- "How does authentication work in this app?"
- "Where is the database connection configured?"
- "Show me all API endpoints"
- "Find the User model"
- "What's the error handling pattern?"
- "Where are tests for the login feature?"
❌ Should NOT Activate
- "How do I write async code?" (general question)
- "What does FastAPI's Depends do?" (external library)
- "Should we refactor this?" (architectural question)
- "What's our testing strategy?" (process question)
- [Project not indexed] + any code question (defer to setup-assistant)
Success Criteria
This skill is successful when:
- User's code questions get answered automatically
- Relevant code is surfaced without manual search
- User doesn't need to remember to use
/searchcommand - Feels "invisible" - just works naturally
- Doesn't activate on non-code questions (low false positive rate)
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
setup-assistant
Detect when user is working in an un-indexed project and proactively suggest enabling semantic memory. Activates on first code question in new projects to guide users through initial setup.
example-helper
Example skill demonstrating Claude Code capabilities. Activates when user mentions "example", "demo", or "template". Shows how to create effective Skills with proper structure. Use when user wants to see skill examples or understand skill creation.
plugin-scaffolder
Scaffolds complete Claude Code plugin structures with all necessary directories, manifest, and documentation. Activates when user wants to create a new plugin, package features together, or prepare for marketplace distribution. Creates plugin.json, directory structure, and starter documentation. Use when user mentions "create plugin", "new plugin", "scaffold plugin", "plugin structure", or "share via marketplace".
skill-generator
Generates new Claude Code Skills with intelligent defaults. Activates when user discusses creating a new skill, capability, or reusable workflow. Infers purpose from context, creates proper YAML frontmatter, suggests tool restrictions, and sets up supporting file structure. Use when user mentions "create a skill", "new skill", "skill for", or discusses adding reusable capabilities.
hook-generator
Creates and configures Claude Code hooks for event-driven automation. Activates when user wants to automate tasks, create event handlers, add formatting/logging/notifications, or ensure deterministic behaviors. Updates settings.json safely with hook configurations. Use when user mentions "create hook", "automate", "on save", "pre/post tool", "notification", "formatting hook", or wants always-on behaviors.
subagent-generator
Generates custom Claude Code subagents with specialized expertise. Activates when user wants to create a subagent, specialized agent, or task-specific AI assistant. Creates properly formatted .md files with YAML frontmatter, suggests tool restrictions and model selection, generates effective system prompts. Use when user mentions "create subagent", "new agent", "specialized agent", "task-specific agent", or wants isolated context for domain-specific work.
Didn't find tool you were looking for?