Local Service Reference¶
Service ¶
A service for interacting with local Lean explore data.
This service loads necessary data assets (embedding model, FAISS index, database connection) upon initialization using default paths and parameters derived from the active toolchain. It provides methods for searching statement groups, retrieving them by ID, and fetching dependencies (citations).
Attributes:
| Name | Type | Description |
|---|---|---|
embedding_model |
Optional[SentenceTransformer]
|
The loaded sentence embedding model. |
faiss_index |
Index
|
The loaded FAISS index. |
text_chunk_id_map |
List[str]
|
A list mapping FAISS indices to text chunk IDs. |
engine |
The SQLAlchemy engine for database connections. |
|
SessionLocal |
sessionmaker[Session]
|
The SQLAlchemy sessionmaker for creating sessions. |
default_faiss_k |
int
|
Default number of FAISS neighbors to retrieve. |
default_pagerank_weight |
float
|
Default weight for PageRank. |
default_text_relevance_weight |
float
|
Default weight for text relevance. |
default_name_match_weight |
float
|
Default weight for name matching (BM25). |
default_semantic_similarity_threshold |
float
|
Default similarity threshold. |
default_results_limit |
int
|
Default limit for search results. |
default_faiss_nprobe |
int
|
Default nprobe for FAISS IVF indexes. |
default_faiss_oversampling_factor |
int
|
Default oversampling factor for FAISS when package filters are active. |
Initializes the Service by loading data assets and configurations.
Checks for essential local data files first, then loads the
embedding model, FAISS index, and sets up the database engine.
Paths for data assets are sourced from lean_explore.defaults.
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If essential data files (DB, FAISS index, map) are not found at their expected locations. |
RuntimeError
|
If the embedding model fails to load or if other critical initialization steps (like database connection after file checks) fail. |
Source code in src/lean_explore/local/service.py
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 | |
Functions¶
get_by_id ¶
Retrieves a specific statement group by its ID from local data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
group_id
|
Union[int, List[int]]
|
The unique identifier of the statement group, or a list of IDs. |
required |
Returns:
| Type | Description |
|---|---|
Union[Optional[APISearchResultItem], List[Optional[APISearchResultItem]]]
|
An APISearchResultItem if a single ID was found, None if not found. |
Union[Optional[APISearchResultItem], List[Optional[APISearchResultItem]]]
|
A list of Optional[APISearchResultItem] if a list of IDs was provided. |
Source code in src/lean_explore/local/service.py
get_dependencies ¶
Retrieves citations for a specific statement group from local data.
Citations are the statement groups that the specified group_id depends on.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
group_id
|
Union[int, List[int]]
|
The unique ID of the source group, or a list of IDs. |
required |
Returns:
| Type | Description |
|---|---|
Union[Optional[APICitationsResponse], List[Optional[APICitationsResponse]]]
|
An APICitationsResponse if a single ID was provided, or a list of |
Union[Optional[APICitationsResponse], List[Optional[APICitationsResponse]]]
|
Optional[APICitationsResponse] if a list of IDs was given. Returns |
Union[Optional[APICitationsResponse], List[Optional[APICitationsResponse]]]
|
None for IDs that are not found or cause an error. |
Source code in src/lean_explore/local/service.py
402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 | |
search ¶
Performs a local search for statement groups.
This method can handle a single query string or a list of query strings. When a list is provided, searches are performed serially.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
Union[str, List[str]]
|
The search query string or a list of query strings. |
required |
package_filters
|
Optional[List[str]]
|
An optional list of package names to filter results by. |
None
|
limit
|
Optional[int]
|
An optional limit on the number of results to return. If None, defaults.DEFAULT_RESULTS_LIMIT is used. |
None
|
Returns:
| Type | Description |
|---|---|
Union[APISearchResponse, List[APISearchResponse]]
|
An APISearchResponse object if a single query was provided, or a |
Union[APISearchResponse, List[APISearchResponse]]
|
list of APISearchResponse objects if a list of queries was provided. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If service not properly initialized (e.g., assets missing). |
Exception
|
Propagates exceptions from |