Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:0xranx OpenContext Search Types

From Leeroopedia
Knowledge Sources
Domains Search, Rust_Core
Last Updated 2026-10-24 00:00 GMT

Overview

Common type definitions for the search module, including chunks, search options, search hits, and search results, provided by the Rust core library.

Description

The types module in crates/opencontext-core/src/search/types.rs defines the shared data structures used across the entire search pipeline. It contains Chunk (an embedded document fragment with its vector), TextChunk (a pre-embedding text fragment), SearchOptions (query parameters), SearchHit (a single search result), and SearchResults (the aggregate response). These types use serde for JSON serialization and are consumed by both the Rust indexer and the Node.js NAPI layer.

Usage

Import these types when building search-related Rust modules in the opencontext-core crate, or when the NAPI binding layer needs to understand the shape of data returned to Node.js.

Code Reference

Source Location

Signature

pub struct Chunk {
    pub id: String,
    pub file_path: String,
    pub content: String,
    pub heading_path: String,
    pub section_title: Option<String>,
    pub doc_type: Option<String>,
    pub entry_id: Option<String>,
    pub entry_date: Option<String>,
    pub entry_created_at: Option<String>,
    pub idea_box: Option<String>,
    pub chunk_index: usize,
    pub vector: Vec<f32>,
}

pub struct TextChunk {
    pub content: String,
    pub heading_path: String,
    pub start_line: usize,
    pub end_line: usize,
}

pub enum SearchMode { Vector, Keyword, Hybrid }
pub enum AggregateBy { Content, Doc, Folder }
pub enum MatchType { Vector, Keyword, Hybrid }

pub struct SearchOptions {
    pub query: String,
    pub limit: Option<usize>,
    pub mode: Option<SearchMode>,
    pub aggregate_by: Option<AggregateBy>,
    pub doc_type: Option<String>,
}

pub struct SearchHit {
    pub file_path: String,
    pub display_name: String,
    pub content: String,
    pub heading_path: Option<String>,
    pub section_title: Option<String>,
    pub line_start: Option<usize>,
    pub line_end: Option<usize>,
    pub score: f32,
    pub matched_by: MatchType,
    pub hit_count: Option<usize>,
    pub doc_count: Option<usize>,
    pub folder_path: Option<String>,
    pub aggregate_type: Option<String>,
    pub doc_type: Option<String>,
    pub entry_id: Option<String>,
    pub entry_date: Option<String>,
    pub entry_created_at: Option<String>,
    pub idea_box: Option<String>,
}

pub struct SearchResults {
    pub query: String,
    pub results: Vec<SearchHit>,
    pub count: usize,
    pub mode: Option<String>,
    pub aggregate_by: Option<String>,
    pub index_missing: Option<bool>,
    pub error: Option<String>,
}

Import

use opencontext_core::search::types::{Chunk, TextChunk, SearchMode, SearchOptions, SearchHit, SearchResults};

I/O Contract

Inputs

Name Type Required Description
query String Yes The search query text
limit Option<usize> No Max results (default 10)
mode Option<SearchMode> No Vector, Keyword, or Hybrid (default Hybrid)
aggregate_by Option<AggregateBy> No Content, Doc, or Folder (default Doc)
doc_type Option<String> No Filter by "doc" or "idea"

Outputs

Name Type Description
SearchResults struct Complete search response with hits, count, mode info
SearchHit struct Individual result with score, match type, and metadata
Chunk struct Embedded text chunk with vector for indexing

Usage Examples

Creating Search Options

use opencontext_core::search::types::{SearchOptions, SearchMode, AggregateBy};

let opts = SearchOptions {
    query: "how to train models".to_string(),
    limit: Some(20),
    mode: Some(SearchMode::Hybrid),
    aggregate_by: Some(AggregateBy::Doc),
    doc_type: None,
};

// Access resolved defaults
assert_eq!(opts.limit(), 20);
assert_eq!(opts.mode(), SearchMode::Hybrid);

Building Empty/Error Results

use opencontext_core::search::types::SearchResults;

// Empty result set
let empty = SearchResults::empty("query".to_string());

// Error result
let errored = SearchResults::with_error("query".to_string(), "API key missing".to_string());

// Index not built indicator
let not_built = SearchResults::index_not_built("query".to_string());
assert_eq!(not_built.index_missing, Some(true));

Related Pages

</content> </invoke>

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment