Search indexed files using natural language queries with hybrid semantic and keyword search.
Request
Natural language search queryExamples:
- “tax documents from 2023”
- “python code with API calls”
- “meeting notes about project roadmap”
Maximum number of results to return (1-100)
Minimum combined score threshold (0.0-1.0)
Request Example
curl "http://localhost:60534/api/search/stream?query=meeting+notes&limit=10"
import requests
response = requests.get(
'http://localhost:60534/api/search/stream',
params={
'query': 'meeting notes',
'limit': 10,
'min_score': 0.2
}
)
for result in response.json()['data']['results']:
print(f"{result['title']}: {result['path']}")
const params = new URLSearchParams({
query: 'meeting notes',
limit: 10,
min_score: 0.2
});
const response = await fetch(
`http://localhost:60534/api/search/stream?${params}`
);
const data = await response.json();
data.data.results.forEach(result => {
console.log(`${result.title}: ${result.path}`);
});
Response
Status of the request: success or error
The search query that was executed
Total number of results found
Array of search results sorted by score (descending)
Absolute path to the file
AI-generated title for the file
AI-generated summary (max 100 words)
Array of 3-5 relevant keywords
Combined search score (0.0-1.0)
- Semantic score: 0.0-0.5
- Keyword score: 0.0-0.5
Vector similarity score component
FTS5 keyword match score component
Response Example
{
"status": "success",
"data": {
"query": "meeting notes",
"total_results": 8,
"results": [
{
"path": "/Users/username/Documents/Q4-planning-meeting.md",
"title": "Q4 Planning Meeting Notes",
"summary": "Discussion of Q4 roadmap including feature priorities, resource allocation, and timeline adjustments. Key decisions on API redesign and mobile app launch.",
"keywords": ["planning", "Q4", "roadmap", "meeting", "decisions"],
"score": 0.89,
"semantic_score": 0.47,
"keyword_score": 0.42
},
{
"path": "/Users/username/Documents/standup-2024-01-15.txt",
"title": "Daily Standup - January 15",
"summary": "Team standup covering progress on authentication system, blockers with database migrations, and upcoming sprint planning meeting.",
"keywords": ["standup", "meeting", "progress", "blockers"],
"score": 0.73,
"semantic_score": 0.38,
"keyword_score": 0.35
}
]
}
}
{
"status": "error",
"error": {
"code": "INVALID_QUERY",
"message": "Query must be at least 2 characters"
}
}
Search Algorithm
CosmaSense uses a hybrid search approach combining:
1. Semantic Search (Vector Similarity)
- Embeds your query using e5-base-v2 model
- Calculates cosine similarity against file embeddings
- Score formula:
exp(-distance) scaled to 0-0.5
2. Keyword Search (FTS5)
- SQLite FTS5 full-text search on content, title, and keywords
- Uses BM25 ranking algorithm
- Score scaled to 0-0.5 range
3. Combined Scoring
final_score = semantic_score + keyword_score
This approach ensures:
- Semantic matches for conceptually similar content
- Exact matches for specific terms and phrases
- Best of both worlds with additive scoring
The TUI automatically throttles search requests to 0.5 seconds to prevent excessive API calls while typing.