distx_schema/lib.rs
1//! # DistX Schema
2//!
3//! Structured similarity layer for vector databases.
4//!
5//! ## Overview
6//!
7//! DistX is a Qdrant-compatible vector database. The Schema module adds
8//! structured similarity scoring on top of vector search results.
9//!
10//! **How it works:**
11//! 1. Client generates embeddings for text fields (OpenAI, Cohere, etc.)
12//! 2. Client sends vectors + payload to DistX
13//! 3. DistX performs vector search (ANN)
14//! 4. Schema reranks results using structured field comparisons
15//!
16//! ## Use Cases
17//!
18//! - **Product similarity**: Vector search finds semantically similar products,
19//! schema reranks by price proximity, category match, availability
20//! - **Customer matching**: Vector search on profile text, schema scores by
21//! industry match, company size, location
22//! - **Document search**: Vector search on content, schema weights by
23//! date recency, author, document type
24//!
25//! ## Schema Definition
26//!
27//! ```rust
28//! use distx_schema::{SimilaritySchema, FieldConfig, DistanceType};
29//! use std::collections::HashMap;
30//!
31//! let mut fields = HashMap::new();
32//! // Text fields use vector search (no schema config needed for embedding)
33//! fields.insert("name".to_string(), FieldConfig::text(0.3));
34//! // Numeric fields use relative distance
35//! fields.insert("price".to_string(), FieldConfig::number(0.3, DistanceType::Relative));
36//! // Categorical fields use exact match
37//! fields.insert("category".to_string(), FieldConfig::categorical(0.2));
38//! fields.insert("availability".to_string(), FieldConfig::categorical(0.2));
39//!
40//! let schema = SimilaritySchema::new(fields);
41//! ```
42//!
43//! ## Reranking Flow
44//!
45//! ```text
46//! ┌─────────────┐ ┌─────────────┐ ┌─────────────┐
47//! │ Client │────>│ DistX │────>│ Reranker │
48//! │ (embedding) │ │ (ANN search)│ │ (schema) │
49//! └─────────────┘ └─────────────┘ └─────────────┘
50//! │
51//! ┌──────┴──────┐
52//! │ Explained │
53//! │ Results │
54//! └─────────────┘
55//! ```
56
57pub mod schema;
58pub mod distance;
59pub mod rerank;
60pub mod explain;
61
62// Re-export main types
63pub use schema::{
64 SimilaritySchema,
65 FieldConfig,
66 FieldType,
67 DistanceType,
68 SchemaError,
69};
70pub use rerank::{Reranker, RankedResult};
71pub use explain::{ExplainedResult, SimilarResponse, SimilarityStats, PointIdSer};