Algorithm choices

Run independent algorithms

Use fixture callbacks to compare algorithm choices. Install the optional solver extra to include native graph and centroid-linkage operations.

python -m examples.algorithm_choices_demo
pip install 'mari-kit[algorithm-solvers]'
python -m examples.algorithm_choices_demo --solvers

Mari Kit is a collection of independently selectable algorithms for knowledge and memory workloads. This guide covers the whole package: retrieval, subset selection, parsing, memory, graph analysis, agent experience, maintenance, verification, and evaluation. Similar methods remain available because their tradeoffs differ. Each workload table names the public implementation and links to its detailed behavior and sources.

The complete module and API index accounts for every public implementation module, including the contracts, connectors, and adapters that support algorithms. Module paths in the tables are relative to mari_kit. The index links definitions to inspected source lines. A source citation identifies provenance or a related method. Individual pages explain which computations Mari implements and which model calls the host supplies.

Find a choice by workload

Workload

Compare

Retrieve candidates

Lexical, sparse, dense, approximate, multi-vector, and graph retrieval

Select useful context

Relevance, MMR, coverage, diversity, cost, and source structure

Adapt a retrieval session

HyDE, RAPTOR, MemWalker, CRAG, FLARE, Self-RAG, and DRIFT

Parse and align knowledge

Structured parsers, semantic atoms, diff algorithms, and byte chunking

Organize memory

Admission, mutation, salience, heat, LFU, consolidation, and evolution

Analyze and construct graphs

Paths, communities, entity resolution, linkage, time, and provenance

Learn from agent activity

Episodes, intents, process mining, comparisons, procedures, and feedback

Maintain changing knowledge

Snapshot planning, indexed updates, lineage, reversible aggregates, and replay

Assess evidence and decisions

Grounding, contradiction, consensus, trust, and authority

Evaluate a choice

Retrieval, graph, memory, statistical, and configuration comparisons

Supply integration boundaries

Source adapters, identity, stores, schemas, and portability

Retrieve candidates

Choice and public implementation

Useful workload and tradeoff

Details and sources

retrieval.indexes.BM25Index, ArtifactBM25Index, RevisionBM25Index

Exact terms, identifiers, and symbols with positive-IDF scoring. Artifact/revision wrappers preserve their respective identities.

Lexical indexing, BM25

algorithms.lexical.BM25VariantIndex

Compare rank_bm25 Okapi, L, and Plus formulas for length/repetition effects. L/Plus can score nonmatches above zero.

A01, rank_bm25

retrieval.indexes.SparseVectorIndex

Exact search over caller-supplied sparse weights. The host supplies lexical or learned sparse representations.

Sparse indexing, SPLADE representation research

retrieval.indexes.DenseFlatIndex

Exact vector-search baseline for bounded corpora. Search examines the candidate vectors.

Dense indexing, DPR

retrieval.indexes.HNSWIndex, IVFPQIndex

Approximate graph search or coarse partitioning with product quantization. Measure recall against the flat index.

Index behavior, HNSW, PQ

retrieval.muvera.encode_fde, retrieval.index.build_index / search_index, retrieval.maxsim.exact_maxsim

Fixed-dimensional candidate generation for token-level multi-vector retrieval followed by exact late-interaction reranking.

MUVERA composition, MUVERA, ColBERT

retrieval.polarquant.train_polar / encode_polar / polar_scores

Mari’s specific packed block-2 Polar codec for MUVERA FDE candidate scoring. Quantization trades representation detail for compactness.

Codec behavior, Mari implementation

retrieval.atoms.aggregate_atom_hits, maxsim_section_score

Aggregate atom hits to parent sections or score section token vectors. Parent aggregation and true MaxSim answer different scoring questions.

Atom and section retrieval, ColBERTv2

retrieval.contradiction.rank_sparse_contradictions, sparse_contrastive_losses

Retrieve same-topic contradiction candidates using similarity and difference sparsity. The training-loss helper leaves model training external.

SparseCL boundary, SparseCL

retrieval.graph.personalized_pagerank, project_graph_scores

Propagate caller seed weights through allowed topology and project node scores to passages.

Graph recall, HippoRAG

algorithms.graph_retrieval.hipporag_seed_weights, expand_typed_links

Build fact/entity/dense seeds before propagation, or perform one entity/semantic/causal expansion step.

A06, A11, HippoRAG, Hindsight

retrieval.fusion.reciprocal_rank_fusion

Combine ranked lists whose score scales differ. Rank fusion discards score magnitude.

Fusion, RAG-Fusion

algorithms.graph_retrieval.rank_candidate_union

Score a union using one embedding space or one shared reranker. Explicit source identity handles cross-collection results.

A21, haiku.rag

algorithms.graph_retrieval.rank_graph_distances, rank_episode_mentions

Prefer supplied graph locality or episode frequency, with explicit handling of missing values.

A12, Graphiti

Select useful context

Choice and public implementation

Useful workload and tradeoff

Details and sources

retrieval.fusion.maximal_marginal_relevance

Balance query relevance against similarity to selected items. A direct option for repetitive search results.

MMR usage, Mari implementation

retrieval.composition.select_context, select_context_diverse

Select artifact-neutral items with budgets, constraints, and explicit decision traces. Diversity-aware selection exposes candidate gains per round.

Context selection, submodular maximization

algorithms.subsets.FacilityLocation

Represent the candidate collection by maximizing best-covered similarity per represented row. Optional query caps focus coverage.

A02, Submodlib

algorithms.subsets.LogDeterminant

Favor distinct vector directions when selecting memories or evidence. Relevance and mandatory retention constraints need explicit treatment.

A02, DPPs

algorithms.subsets.SetCover, ProbabilisticSetCover

Cover caller-defined concepts with binary or probabilistic incidence and optional concept weights.

A02, Submodlib

algorithms.subsets.maximize_subset

Select naive, lazy, stochastic, or lazier greedy independently of the objective. Lazy modes require submodularity.

A03, Submodlib optimizers

retrieval.context.assemble_context, retrieval.composition.hydrate_hits

Resolve IDs and assemble bounded source content with exclusions and missing-hit traces.

Context envelopes, Mari context implementation

retrieval.atoms.assemble_atom_context, retrieval.structure.expand_structured_context

Expand retrieved atoms into neighboring context or preserve section structure, exact spans, and original hits.

Atom context, evidence context, haiku.rag

algorithms.graph_retrieval.weighted_chunk_polling

Allocate descending per-parent chunk quotas and redistribute unused quota. Maximum denotes a parent quota.

A08, LightRAG

retrieval.research.selective_compression, algorithms.compression.select_surprising_words

Compare caller-scored sentence selection with token-surprisal word selection. Both produce extractive content.

RECOMP-style boundary, RECOMP, A13, LightMem

knowledge.compaction.plan_evidence_compaction, knowledge.multimodal.select_evidence_assets

Preserve evidence groups through compaction and bind image/page/media assets to retained evidence.

Evidence context, haiku.rag

Log-determinant and facility location answer different questions. Log-determinant rewards distinct contributions in the selected feature space. Facility location rewards representation of the broader supplied collection. Explicit set cover is useful when the host can name the requirements it needs covered. MMR combines relevance and redundancy directly. None of these choices establishes factual correctness or independent corroboration from embeddings alone.

Adapt a retrieval session

Choice and public implementation

Useful workload and tradeoff

Details and sources

retrieval.research.hypothetical_document_embedding

Embed a generated hypothetical answer/document to change the query representation. Generation and embedding callbacks belong to the host.

Construction, HyDE

retrieval.research.build_summary_tree, walk_summary_tree

Build a recursive summary hierarchy and navigate it with bounded caller decisions.

Tree construction and navigation, RAPTOR, MemWalker

retrieval.research.plan_corrective_retrieval, plan_active_retrieval

Select corrective retrieval actions from relevance signals or additional queries from uncertain generated content.

Adaptive policies, CRAG, FLARE

verification.research.score_self_rag_candidate

Combine caller-supplied reflection signals to rank a candidate. Reflection generation and the complete Self-RAG model remain external.

Self-RAG boundary, Self-RAG

algorithms.search.drift_search

Prime questions, expand ranked follow-ups within budgets, and reduce completed answers.

A07, GraphRAG DRIFT

retrieval.sufficiency.assess_context_sufficiency, parse_retrieval_gap_queries, evaluate_context_contribution

Check explicit requirements, propose gap queries, and measure utility relative to consumed context.

Sufficiency and contribution, PlugMem

retrieval.disclosure.evaluate_disclosure, expand_disclosure, lifecycle.select_intervention

Apply conditional disclosure, progressively expand source detail, or select a lifecycle intervention. Authorization remains a separate host input.

Lifecycle and disclosure, Nocturne

retrieval.contextual.contextual_representation, pool_token_spans

Attach validated context to chunks or pool supplied token vectors across source spans.

Contextual representations, Late Chunking

Parse and align knowledge

Choice and public implementation

Useful workload and tradeoff

Details and sources

documents.markdown.parse_markdown, documents.html.parse_html, documents.records.parse_delimited / parse_json_lines / parse_json_array

Parse text structure and records into source-addressable values. Format-specific fidelity is described in the parser guides.

Source parsers, Mari parser implementation

documents.code.parse_python, documents.impacted_symbols

Extract Python symbols/references and find symbols affected by source changes.

Code knowledge, Codebase-Memory

documents.tables.normalize_table, documents.docling.adapt_docling_json

Normalize table structure or adapt supplied Docling JSON with text, cells, page regions, and references.

Structured documents, evidence context, Docling

documents.atoms.semantic_atoms, content_defined_spans, active_atoms

Use stable structural units, text-oriented content-defined fallback spans, and temporal versions. Text span boundaries differ from byte FastCDC.

Semantic atoms, Mari atom implementation

documents.sequence_diff.myers_diff, patience_diff, documents.atoms.align_atoms

Compare minimum-edit alignment with unique-anchor alignment for changed sources.

Revision alignment, Myers

algorithms.compression.fastcdc_chunks

Deduplicate byte streams with read-pattern-independent content-defined boundaries and owned chunks.

A14, FastCDC

knowledge.facts.parse_facts, parse_claim_assessments, deduplicate_fact_candidates, plus decisions/glossary/answers/summaries/refinement parsers

Validate caller-generated structured knowledge. Parsing a proposed claim provides a different guarantee from proving it.

Task-specific parsers, FActScore, QASPER

algorithms.search.refine_extraction

Run bounded glean passes with explicit identity and merge policies.

A09, LightRAG

knowledge.sections.document_sections, knowledge.excerpt.excerpt, knowledge.tags.assign_tags, knowledge.links.extract_explicit_links / derive_links

Select source sections/excerpts, assign normalized tags, and derive explicit links.

Sections, Tags, Mari link implementation

Organize memory

Choice and public implementation

Useful workload and tradeoff

Details and sources

knowledge.admission.admit_candidate

Accept, defer, reject, or quarantine from explicit admission signals and thresholds.

Admission, Mari admission policy

knowledge.mutations.plan_memory_mutations, apply_memory_mutations

Validate add/update/delete/no-op decisions against existing memories. The host supplies decisions and durable transactions.

Memory mutations, Mem0

knowledge.segmentation.hybrid_topic_segments, knowledge.consolidation.plan_consolidation

Segment topic changes and choose bounded offline work from utility/cost signals.

Consolidation, LightMem, MemoryOS

knowledge.research.rank_salient_memories

Combine recency, importance, and relevance using the existing salience policy.

Memory organization, Generative Agents

algorithms.temporal.recency_decay, dated_recency, temporal_proof_score

Compare linear/exponential/neutral freshness and proportional temporal/proof boosts to relevance.

A10, Hindsight

algorithms.memory.memory_heat, lfu_evictions, heat_promotions

Raw visit/interaction/recency heat, least-frequency eviction, and above-threshold promotion are independent policies.

A15, MemoryOS

knowledge.research.plan_note_evolution, algorithms.memory.evolve_neighborhood

Compare the existing note-link plan with callback-proposed context/tag/link updates guarded by expected revisions.

Note organization, A18, A-MEM

verification.research.decide_from_evidence_notes

Decide an answer source from sequential evidence-note judgments supplied by the host.

Evidence-note decisions, Chain-of-Note

algorithms.memory.reduce_skill_feedback

Reduce helpful/harmful/neutral feedback and explicit keep/update/delete/merge decisions with provenance.

A19, ACE

governance.propose_promotion, plan_retention, evaluate_purpose

Propose scope changes and retention actions under caller policies. These are planning decisions with host-owned persistence.

Scopes, Retention, Mari governance implementation

Analyze and construct graphs

Choice and public implementation

Useful workload and tradeoff

Details and sources

graph.traversal.breadth_first, k_hop_nodes, shortest_path, traverse_edges, predecessor_dag

Reachability, paths, edge-aware traversal, and alternate predecessor explanations.

Traversal and paths, Dijkstra

graph.traversal.connected_components, directed_cycles, algorithms.graphs.condense_graph

Identify connectivity, cycles, or strongly connected components and their condensation DAG.

Traversal, A20, NetworkX

algorithms.graphs.transitive_reduction_edges, cohesive_subgraph

Reduce redundant DAG edges or select topological k-core/k-truss membership.

A20, NetworkX

graph.subgraphs.bounded_seed_expansion, prize_guided_subgraph, algorithms.graphs.prize_collecting_forest

Compare bounded expansion, the local greedy prize heuristic, and the native PCST approximation for connecting useful evidence.

Subgraph selection, A04, G-Retriever, pcst_fast

graph.centrality.degree_centrality, closeness_centrality, betweenness_centrality, hits

Rank local connectivity, distance, bridge position, or hub/authority structure. Different centralities encode different notions of importance.

Structural ranking, Brandes

graph.similarity.score_link_candidates, simrank_scores

Score common-neighbor/Jaccard/Adamic–Adar links or recursive structural similarity.

Link prediction, SimRank

graph.communities.leiden_communities, algorithms.graphs.louvain_partition, hierarchical_leiden_partition

Compare the historical local-modularity heuristic, NetworkX Louvain, and native hierarchical Leiden. Only the native adapter provides full hierarchical Leiden.

Community behavior, A05, Louvain, Leiden

graph.communities.build_community_reports, map_reduce_reports

Generate community reports and reduce report-level query results through bounded callbacks.

Corpus aggregation, GraphRAG

graph.resolution.fellegi_sunter_score, resolve_entity

Combine field-level agreement evidence into match/review/nonmatch decisions.

Entity resolution, Fellegi–Sunter

graph.construction.candidate_pairs, explain_candidate_pairs, cluster_matches, inspect_clusters

Build blocked pairs, inspect pair provenance, and cluster supplied match links with diagnostics.

Construction tools, Dedupe

algorithms.linkage.learn_blocking, acquire_disagreement

Learn a predicate disjunction under coverage/cost constraints and acquire informative matcher/blocker disagreements.

A16, Dedupe

algorithms.linkage.centroid_clusters, greedy_matching, gazette_matching

Compare same-entity clustering, one-to-one greedy assignment, and reusable-right-record lookup.

A17, Dedupe

graph.temporal.query_temporal_facts, close_transaction, graph.temporal_tools.temporal_join, grouped_interval_overlaps

Query valid/transaction time and join interval-bearing records. Interval semantics are explicit.

Temporal graphs, Temporal operations, Graphiti

graph.provenance.trace_lineage, trace_lineage_edges, propagated_taints, graph.evidence_projection.project_graph_evidence

Explain derivation paths, propagate taints, and project graph selections to bound evidence.

Provenance, Evidence projection, Mari provenance

graph.diagnostics.graph_diff, diff_records, diff_record_fields, inspect_graph_quality, knowledge.versions.resolve_version_families

Inspect structural/field drift, graph quality, and revision families. Diagnostics describe supplied data.

Graph differences, Version families, Mari diagnostics

Learn from agent activity

Choice and public implementation

Useful workload and tradeoff

Details and sources

conversation_knowledge.segment_conversations, compile_episodes, conversation_topics.semantic_conversation_episodes, semantic_topic_groups, compile_topic_briefs

Compare thread/time segmentation with embedding-based complete-link episode/topic grouping. Compilation uses supplied extraction/consolidation callbacks and revision-bound evidence.

Conversation knowledge, LightMem, Mari topic grouping

trajectories.normalize.normalize_steps, trajectories.adapters.normalize_openai_trajectory / normalize_anthropic_trajectory / normalize_otel_trajectory, trajectories.traces.normalize_genai_trace

Normalize observed activity and preserve trace integrity before comparing behavior. These are format adapters and validators.

Trajectory normalization, Hodoscope, OpenTelemetry GenAI

trajectories.episodes.segment_episodes, parse_turn_assessments, parse_episode_reflection

Segment bounded activity and validate caller assessments/reflections.

Trajectories, Reflexion

trajectories.process.mine_trajectory_process, trajectories.matching.trajectory_edit_distance, compare_trajectories

Mine activity/transition frequencies and compare ordered execution paths.

Process and path mining, TraceRoutine, AgentEvals

trajectories.invariants.mine_trajectory_invariants, check_trajectory_invariant, trajectories.sampling.select_diverse_trajectories

Find observed invariants and choose varied traces for inspection. Observed invariants need held-out validation.

Invariant mining and sampling, Trace-to-Evals

trajectories.intents.aggregate_intents, summarize_intent_reviews, trajectories.intent_analysis.cluster_intents, detect_novel_intents, compare_intent_windows

Aggregate inferred intents, cluster examples, detect novelty, and compare changing distributions.

Intent analysis, intent decomposition, Jensen–Shannon divergence

trajectories.rubrics.score_trajectory_rubric, trajectories.experience.mine_outcome_associations, compare_reasoning_memories

Apply explicit rubrics and compare outcome-associated reasoning memories with uncertainty estimates.

Intent/rubric analysis, Experience knowledge, AdaRubric

trajectories.procedures.learn_procedure, trajectories.mine.parse_trajectory_analysis

Turn supplied activity analysis into a procedure candidate. The callback/evaluation boundary determines quality.

Procedures, Procedural learning, Voyager

trajectories.workflows.match_reviewed_workflow, match_cached_response, decide_reviewed_workflow, start_speculative_retrieval

Match reviewed workflows or cached answers and choose policy actions with explicit freshness checks.

Workflow decisions, GPTCache

knowledge.experience.build_knowledge_use_manifest, parse_feedback_diagnoses, parse_experience_knowledge, parse_knowledge_change, knowledge.observations.inspect_knowledge_observations

Record what knowledge an agent saw/used, diagnose feedback, and propose bounded edits.

Experience knowledge, PlugMem, ReasoningBank

Maintain changing knowledge

Choice and public implementation

Useful workload and tradeoff

Details and sources

dependencies.plan_dependency_updates, incremental.DependencyIndex

Compare complete snapshot planning with an indexed affected frontier. Inputs, derivations, and completed receipts drive reuse/rebuild decisions.

Dependency updates, Incremental maintenance, Mari planner

selections.plan_selection, complete_selection, grouping.reconcile_groups

Track changes to selection membership and preserve group identity through split/merge/regrouping using member overlap.

Incremental maintenance, Mari grouping

aggregates.DeltaAggregate, CountReducer, WeightedVectorReducer, LexicalStatisticsReducer, MembershipReducer

Apply reversible keyed updates to counts, vectors, lexical statistics, or membership. Single-writer reference aggregates expose host persistence boundaries.

Delta aggregates, Mari reducers

documents.atoms.plan_atom_refresh, documents.dependencies.atom_dependencies, knowledge.freshness.assess_freshness, impacted_artifacts

Relate source changes to atom work and evidence freshness. Structural refresh and artifact validity are separate decisions.

Atom maintenance, Freshness, Mari freshness

platform.views.plan_view_refresh, platform.projections.replay_projection

Plan derived-view refresh or rebuild projections from ordered events.

Living views, Projection replay, DBSP research context

sync.planning.plan_sync, stream_sync, sync.application.apply_sync_plan, connectors.events.coalesce_hints_ordered

Reconcile complete/incremental source observations and coalesce ordered hints before canonical refetch.

Sync planning, Connectors, Mari sync

knowledge.fact_scans.pending_fact_sections, knowledge.assertions.plan_assertion_update, valid_at

Select stale fact-scan sections and plan assertion revision history.

Freshness, Mari assertions

Assess evidence and decisions

Choice and public implementation

Useful workload and tradeoff

Details and sources

verification.scoring.harmonic_score, idea_completeness, score_grounded, verification.selection.select_best, verification.portfolio.best_of_n, verification.consensus.verdict_consensus

Score supplied evidence signals, select candidate attempts, and aggregate verdicts. Numerical scoring remains separate from claim-generation quality.

Verification, Self-consistency, ALCE

knowledge.aggregation.weighted_mean, wilson_proportion, knowledge.scoring.grounding_coverage

Aggregate evidence with explicit weights/uncertainty and measure cited support coverage.

Numerical verification, Wilson interval

verification.contradiction.validate_document_contradiction, document_contradiction_rewards

Validate within-document contradiction evidence and reference-coverage rewards. Cross-source SparseCL retrieval is a separate choice.

Document contradiction, reference coverage

knowledge.evidence.validate_artifact_evidence, validate_located_evidence, knowledge.citations.inspect_citation_declarations, documents.validation.validate_region_evidence

Check evidence identity, location, regions, and declared citation lifecycles. These checks verify structure and binding.

Evidence, Evidence context, haiku.rag

governance.evaluate_write, inherit_taints, resolve_assertions

Evaluate supplied trust signals, inherited taints, and explicit authority policies for competing assertions.

Trust decisions, Authority conflicts, Mari governance

knowledge.changesets.validate_knowledge_changeset, knowledge.derivations.inspect_knowledge_derivations, knowledge.experience.inspect_knowledge_structure

Validate grouped edits, derivation dependencies/feedback loops, and caller-designed knowledge-file structures.

Experience validation, Nanopublications

retrieval.decisions.filter_with_reasons, diagnose_candidate_history

Trace inclusion/exclusion and cross-stage candidate decisions.

Context decision traces, Mari decision diagnostics

Evaluate a choice

Choice and public implementation

Useful workload and tradeoff

Details and sources

evaluation.metrics.evaluate_retrieval, reciprocal_rank, ndcg_at_k, set_metrics, boundary_metrics, classification_metrics

Measure ranking, set coverage, segmentation, and classification under supplied labels.

Evaluation, Mari metrics

evaluation.graph.evaluate_path, evaluate_link_prediction, evaluate_subgraph, evaluate_clustering, evaluate_graph_context, evaluate_grouped_coverage

Evaluate path/edge/node recovery, clusters, graph-grounded context, and grouped requirements.

Graph diagnostics and measures, Mari graph evaluation

evaluation.statistics.compare_paired_metrics, evaluate_slices, summarize_review_reliability, summarize_repeated_trials

Compare paired outcomes, slices, reviewer agreement, and repeated attempts with uncertainty.

Outcome comparison, Mari statistical implementation

evaluation.metrics.compare_task_outcomes, evaluation.gates.regression_gate, agents.evaluation.evaluate_tools / evaluate_outcome

Check task-level improvements, regression thresholds, and observed tool/outcome behavior.

Task outcomes, Mari gates

platform.compiler.compile_configurations

Compare caller-supplied configurations against explicit metric objectives. The host defines the candidate search space and evaluation.

Configuration compiler, DSPy research context

evaluation.cases.load_beir_cases, load_fever_cases, load_longmemeval_cases, evaluation.catalog, evaluation.suites

Load benchmark cases/catalogs for a consistent comparison. Dataset adapters supply cases rather than algorithm-quality claims.

Memory evaluation, LongMemEval

Supply integration boundaries

These modules are part of the project and appear in the complete index. They supply values, validation, I/O adapters, and execution boundaries rather than alternative ranking objectives.

Area

Public surfaces and purpose

Details and project sources

Identity and structure

references, types, documents, schema, knowledge.artifacts: IDs, revisions, source coordinates, document/region values, semantic records, and schema validation.

Documents, Schemas, Artifacts, Mari package

Source adapters

connectors: Airtable, Asana, Box, Confluence, Dropbox, filesystem, GitHub, GitLab, Google Drive, Jira, JSON API, Linear, Microsoft Drive, Notion, object storage, RSS, Singer, Slack, Trello, Zendesk, and shared event/stream protocols.

Connector capabilities, CloudEvents, Mari connectors

Graph and index interchange

graph.interop, retrieval.serialization: NetworkX/GraphML/JSON-LD/RDFLib/PyG projections and supported index serialization with explicit loss/compatibility checks.

Graph interoperability, Index interfaces, NetworkX

Contracts and storage

contracts, http, errors, json, platform.stores, platform.pipeline, testing: injected interfaces, immutable JSON, canonical serialization, reference stores, stage execution, and conformance checks.

Contracts, Stores, Pipelines, Mari package

Portable bundles

portability.export_bundle, verify_bundle, plan_bundle_import: integrity verification and import planning for knowledge artifacts and evidence.

Portability, Portable Memory

Run and inspect the implementations

from mari_kit.algorithms.subsets import LogDeterminant, maximize_subset
from mari_kit.retrieval.indexes import BM25Index, DenseFlatIndex
from mari_kit.retrieval.fusion import maximal_marginal_relevance
from mari_kit.dependencies import plan_dependency_updates

Imports illustrate independent choices. The feature guides show function signatures and runnable compositions. Use the complete module/API index to locate additional helpers, records, methods, and exact source definitions. Base numerical implementations depend on NumPy. Native graph and centroid operations are loaded lazily through mari-kit[algorithm-solvers].

Some research-inspired boundaries consume model outputs or callbacks. The library supplies the documented computation, validation, or plan. The host supplies models, data, storage, authorization, and execution policy. Exact local fixtures and published paper results answer different evaluation questions.

Detailed source notes

The A01–A21 notes below retain the original stable sections for the September algorithm additions. The workload tables above place those additions alongside the pre-existing choices. Existing families have their detailed source and implementation notes in the linked feature guides.

A01 — BM25 alternatives

lexical.BM25VariantIndex requires explicit BM25Variant.OKAPI, .L, or .PLUS and caller-tokenized documents/query. It returns scores, matched flags, and per-term explanations. It follows rank_bm25’s formulas, including Okapi’s negative-IDF epsilon floor and L/Plus nonmatching baselines. The existing positive-IDF BM25Index remains a separate option.

Choose among them by retrieval evaluation, especially when document lengths or term repetition vary. Scores are not interchangeable across variants/corpora. matching_only=True removes baseline-only hits; allowed_ids restricts outputs, while corpus statistics remain those of the index. Build separate indexes when statistics themselves must be isolated. Empty corpora return no hits; all-empty corpora and zero-length normalization yield finite zero/baseline scores instead of upstream division errors. Query work is proportional to documents × terms.

A02 — Subset objectives

subsets.FacilityLocation, SetCover, ProbabilisticSetCover, and LogDeterminant implement Submodlib objective equations. Each offers evaluate(subset) and marginal_gain(subset, item) over integer candidate indices. Facility location uses represented-row × candidate similarities and sums each row’s best selected similarity. query_similarities adds FL1MI’s cap eta * max(query similarity) per represented row, allowing query-focused coverage.

Set cover uses binary item × concept incidence; probabilistic cover computes sum(weight * (1 - product(1-p))). Log determinant computes log det(K_A + regularization I) for a symmetric PSD kernel and is zero for an empty selection. Choose representation coverage, explicit concept coverage, or kernel diversity according to the workload. Nonnegative kernels/weights and valid probabilities are checked. These dense reference objectives recompute values: logdet evaluation is cubic in selected size, and initial PSD validation is cubic in ground-set size. Arbitrary logdet scaling is not necessarily monotone. See also the project’s Submodlib paper.

A03 — Greedy optimizer choices

subsets.maximize_subset accepts any deterministic objective callback, positive costs, total budget, optional item limit, and GreedyMethod.NAIVE, .LAZY, .STOCHASTIC, or .LAZIER. These adapt the Submodlib optimizer family. Results expose selected indices, marginal gains, costs, objective evaluation counts, and remaining candidates.

Naive recomputes every feasible gain; lazy caches upper bounds; stochastic samples candidates; lazier combines sampling and bounds. Lazy modes require assume_submodular=True. Seeded sampling and index tie breaks are reproducible. The sample size is ceil(n/k * log(1/epsilon)). Sampling guarantees require a monotone submodular cardinality problem, not arbitrary costs. Gain/cost ranking is a heuristic for budgets; no knapsack-optimality claim is made. A sampled nonpositive best gain can stop with unsampled useful candidates remaining.

A04 — Prize-collecting forest solver

graphs.prize_collecting_forest adapts pcst_fast to caller node prizes and edge costs. It returns original IDs/edges and prize/cost totals. A rooted call fixes its required root; an unrooted call can request multiple clusters. Choose it when valuable evidence requires intermediate connectors, including zero-prize nodes. This is the native approximation, not an exact optimal solver. The existing greedy selector remains useful as a different low-overhead choice. Optional allowed_nodes induces the input graph before solving.

A05 — Louvain and hierarchical Leiden

graphs.louvain_partition invokes NetworkX Louvain; hierarchical_leiden_partition invokes graspologic-native using the same engine as GraphRAG’s hierarchical Leiden adapter. Weighted edges, resolution, seed, and optional allowed nodes are explicit. Leiden returns node/community, level, parent, and final-membership records. Isolated nodes get singleton records; max_cluster_size is a splitting target, not a strict guarantee.

Use Louvain for modularity partitions or hierarchical Leiden for multilevel community workflows. Native library versions can change results despite a fixed seed. The historical graph.communities.leiden_communities API is preserved and now explicitly documented as local modularity improvement plus connected splitting; it does not implement full Leiden aggregation.

A06 — HippoRAG2 seed construction

graph_retrieval.hipporag_seed_weights implements the fact/entity/dense passage seed calculation in HippoRAG’s graph search. Fact scores are divided by entity passage frequency, averaged over incident facts, and optionally limited to the best linked entities. Passage scores are min-max normalized and scaled by passage_weight. The result exposes each contribution separately.

Use this for graph recall combining extracted facts and dense passage evidence. The caller provides embeddings, fact filtering, entity links, and graph edges. Allowed IDs are required and filtered before passage normalization. Missing entity frequencies use one; tied passage scores contribute zero. Feed positive combined weights into retrieval.personalized_pagerank; choose a fallback when all weights are zero. This ports seed construction, not HippoRAG2 end to end.

A08 — Weighted chunk polling

graph_retrieval.weighted_chunk_polling follows LightRAG’s quota and polling algorithm. Ordered parents receive descending linear chunk quotas; unused allocation is redistributed by scanning highest-ranked parents first. maximum is the highest-ranked parent quota, not a global cap: total allocation is bounded by the sum of interpolated parent quotas. It returns chunks, per-parent counts, and initial quotas. Use it when graph hits have uneven numbers of attached chunks. Parent order and chunk order are caller policy. Duplicates are retained by default; optional deduplication happens after allocation and does not backfill, so output may be below budget.

A09 — Extraction gleaning

search.refine_extraction adapts LightRAG’s extraction and glean merge to explicit initial/refinement callbacks, record identity, and merge policy. It accumulates additions and revisions until the round budget, a continuation callback, or unchanged merged records stops refinement. Use a longer-description merge to resemble LightRAG’s merge preference, or supply another policy.

The upstream path performs an extra extraction pass when enabled; Mari explicitly generalizes this to a configurable bounded number of rounds. Records must have stable equality and immutable values; merges must preserve identity. There is no hidden model call, storage mutation, or assumption that an additional pass improves extraction accuracy.

A10 — Temporal and proof ranking

temporal.recency_decay, dated_recency, and temporal_proof_score implement Hindsight’s recency and multiplicative scoring. Select linear decay with a 0.1 floor, exponential half-life, or neutral 0.5. Date handling uses the source’s month/year span-length heuristic: age from period end, cap at neutral; otherwise prefer occurrence start, mention, then end. Naive datetimes mean UTC.

Normalized relevance is multiplied by neutral-centered recency, proximity, and log proof-count factors. Use this to make recency a proportional preference without replacing relevance ranking. Dates/proximity/proof counts come from the host. Invalid windows and reversed intervals raise instead of silently using upstream fallbacks. Span length is a heuristic for coarse dates, not inferred certainty about date granularity. Missing dates and proof signals are neutral.

A12 — Graph-distance and episode-mention ranking

graph_retrieval.rank_graph_distances and rank_episode_mentions are explicit adaptations of Graphiti’s search rerankers. Distance ranking uses caller-supplied nonnegative distances, reciprocal score, explicit center score, and zero for unreachable/missing nodes. Mari does not pretend Graphiti’s adjacency query calculates all shortest paths.

Episode ranking defaults to descending mention count, with an ascending option; missing counts sort last. This deliberately differs from the inspected upstream ascending frequency sort. Choose distance for locality and episode count for repetition/popularity, then evaluate which direction suits the workload.

A13 — Source-preserving surprisal selection

compression.select_surprising_words adapts LightMem’s entropy compressor. The caller supplies observed-token probabilities, token spans, and word spans. Word scores aggregate -log2(probability) by mean or first token. The top max(1, floor(words * fraction)) words are returned in source order with original spans and scores; an empty input returns empty output.

Use it for inexpensive extractive compression with an external language model. The host must align next-token probabilities correctly. Explicit spans replace upstream tokenizer-specific grouping; cross-boundary tokens contribute to every overlapping word. The joined text is a selection, not a grammatical summary. The implementation scans token spans per word and does not load Torch/models.

A14 — Byte-stream FastCDC

compression.fastcdc_chunks ports tigerwill90/fastcdc’s byte boundaries, including its gear table, masks, normalization center, integer overflow, and minimum/average/maximum size conventions. It follows the project’s variant of Xia et al., FastCDC (USENIX ATC 2016). Returned ByteChunk values own their bytes and include stream offsets.

Use it for content-defined deduplication of byte streams. Boundaries do not depend on binary reader short-read patterns. Work is linear in bytes and buffered memory is proportional to maximum chunk size; only the last chunk may be below minimum. Blocking read(size) must return bytes; an empty read means EOF and errors propagate. These are byte offsets, not character/token boundaries. Other FastCDC variants can disagree. The port retains the project’s MIT notice and has a fixture generated by its unmodified Go source.

A15 — Raw heat, LFU, and promotion

memory.memory_heat, lfu_evictions, and heat_promotions adapt MemoryOS’s heat and capacity policies. Raw heat is alpha*visits + beta*interactions + gamma*exp(-age_hours/tau_hours); LFU chooses lowest access count; promotion chooses strictly above-threshold heat, hottest first. Stable insertion order resolves ties.

Use them independently for admission, retention, or tiering experiments. The host supplies counts/age, applies returned IDs, and defines capacity. Protection can make eviction infeasible, which raises explicitly. These functions do not copy MemoryOS’s storage or conversation workflow. Unlike timestamp-parsing upstream fallbacks, invalid ages/parameters fail validation.

A16 — Learned blocking and active pair acquisition

linkage.learn_blocking adapts Dedupe’s bounded set-cover search. Caller predicates expose labeled-match coverage and comparison cost. The search minimizes the sum of selected predicate costs while reaching floor(recall * number_of_matches) coverage. It returns selected predicate names, coverage, cost, feasibility, search count, and whether search completed.

Use it to learn a disjunction of existing predicates before expensive pair scoring. Predicate construction, compound predicates, training labels, and the matcher remain external. Search is exponential in the worst case and bounded by max_states; unfinished search can have no feasible incumbent even when a solution exists. Overlapping comparison costs are counted repeatedly.

acquire_disagreement follows Dedupe’s matcher/blocker acquisition policy: prioritize uncovered likely matches, otherwise spread acquisition across covered probabilities, otherwise sample disagreement. Mari uses a single seeded RNG and adds uniform fallback for all-zero weights; it does not promise the identical upstream random sequence.

A17 — Entity clustering and matching choices

linkage.centroid_clusters, greedy_matching, and gazette_matching adapt Dedupe’s matching alternatives. Centroid linkage uses SciPy over 1-score distances, missing pair distance 1, connected components, and per-record 1 - RMS(within-cluster distances) confidence. Singleton outputs are omitted; isolated pairs require score strictly above threshold.

Use clustering for same-entity groups, greedy matching for one-to-one bipartite links, or gazette matching for top matches per left record with reusable right records. None guarantees globally optimal assignment. Centroid distances need not be Euclidean and linkage can invert, as in the source’s chosen method. Clustering takes quadratic memory per component; oversized components raise instead of upstream recursive rethresholding. Repeated undirected pair scores are merged by maximum; greedy ties retain input order.

A18 — Neighborhood memory evolution

memory.evolve_neighborhood adapts A-MEM’s strengthen/update-neighbor actions through a model-agnostic proposal callback. NoteUpdate explicitly addresses note ID and expected revision and may change context/tags or add links. The result contains immutable before/after notes with incremented revisions.

Use it when adding a memory should revise its neighborhood. Duplicate targets, stale revisions, self links, and links outside the supplied neighborhood fail the whole plan. This replaces upstream positional neighbor updates and in-place mutation with explicit identities. The host must atomically compare-and-swap revisions when committing; a generated plan does not reserve those revisions.

A19 — Feedback and skill deduplication

memory.reduce_skill_feedback adapts ACE’s skill feedback and dedup operations. Helpful/harmful/neutral feedback increments counters and preserves provenance; explicit keep/update/delete/merge decisions alter an immutable snapshot. Merge sums source counters, unions provenance, and tombstones sources.

Use it for a host-controlled playbook learning loop. Persist applied_events with the returned snapshot to make feedback replay idempotent. Dedup decisions must be committed once; they are ordered operations, not replayable events. Model evaluation, decision generation, transactions, and eventual garbage collection remain caller choices. Deleted records cannot receive new feedback or be reused in another merge.

A20 — Graph structural alternatives

graphs.condense_graph, transitive_reduction_edges, and cohesive_subgraph expose NetworkX structural algorithms. Condensation returns strongly connected components plus their DAG. Transitive reduction removes redundant DAG edges while retaining reachability and surviving original weights. Cohesion selects topological k-core or k-truss nodes; weights do not change membership.

Use SCCs for cycles, reduction for dependency explanations, and cores/trusses for dense neighborhoods. Reduce only DAGs; condense first when cycles exist. Parallel edges require explicit caller aggregation, and cohesion rejects self loops. These algorithms do not impose application graph semantics.

A21 — Common-space union ranking

graph_retrieval.rank_candidate_union adapts haiku.rag’s search union ordering. Select either cosine scoring across a named common embedding space or scores from a reranker applied to the complete union. Identity is (source, item_id); a required allowed-key set filters candidates before scoring.

Use this when searching several collections with compatible vectors or a shared reranker. The cosine path validates dimensions, space identity, and finite values; zero vectors score zero. The reranker path requires supplied scores for every allowed candidate. Duplicate keys are rejected and deterministic ties retain within-source rank then source arrival order. This does not calibrate unrelated collection scores or independently normalized reranker batches.

Validation and limits

Run the new tests with pytest -q tests/test_algorithm_*.py. The suite includes rank_bm25-generated score fixtures, a Go-generated FastCDC boundary fixture, exhaustive small blocking comparisons, lazy/naive equivalence on random coverage, a PCST bridge case, native graph checks, and callback/scope/revision edge cases. Optional-solver tests skip when dependencies are absent; install the extra to exercise them. CI includes a separate solver job as well as the base test matrix. Local native validation used NetworkX 3.6.1, pcst-fast 1.0.10, graspologic-native 1.3.1, and SciPy 1.18.1 on Python 3.13.

These checks establish the stated computation and interface behaviors on small fixtures. They do not establish retrieval quality, extraction quality, native cross-version reproducibility, or large-scale throughput. Model callbacks and source data require workload-specific evaluation. Source citations acknowledge provenance; adapted interfaces and policies are described above rather than presented as complete upstream systems.