Skip to main content

convergio_knowledge/
types.rs

1//! Types for the knowledge vector store.
2
3use serde::{Deserialize, Serialize};
4
5/// A knowledge entry stored with its embedding.
6#[derive(Debug, Clone, Serialize, Deserialize)]
7pub struct KnowledgeEntry {
8    pub id: String,
9    /// Source type: "task", "commit", "doc", "agent_memory", "kb"
10    pub source_type: String,
11    /// Source identifier (task_id, commit hash, doc path, etc.)
12    pub source_id: String,
13    /// The text content that was embedded.
14    pub content: String,
15    /// Optional org scope.
16    pub org_id: Option<String>,
17    /// Optional agent that produced this.
18    pub agent_id: Option<String>,
19    /// Optional project/repo scope (e.g. "convergio", "istitutodeimpresa").
20    pub project_id: Option<String>,
21    /// Visibility: "org" (default, only within org) or "public" (cross-org federation).
22    #[serde(default = "default_visibility")]
23    pub visibility: String,
24    /// ISO 8601 timestamp.
25    pub created_at: String,
26}
27
28/// Result of a vector similarity search.
29#[derive(Debug, Clone, Serialize, Deserialize)]
30pub struct SearchResult {
31    pub entry: KnowledgeEntry,
32    /// Cosine similarity score (0.0 to 1.0).
33    pub score: f64,
34}
35
36/// Request to write a knowledge entry.
37#[derive(Debug, Deserialize)]
38pub struct WriteRequest {
39    pub content: String,
40    pub source_type: String,
41    pub source_id: String,
42    #[serde(default)]
43    pub org_id: Option<String>,
44    #[serde(default)]
45    pub agent_id: Option<String>,
46    #[serde(default)]
47    pub project_id: Option<String>,
48    /// Visibility: "org" (default) or "public".
49    #[serde(default = "default_visibility")]
50    pub visibility: String,
51}
52
53fn default_visibility() -> String {
54    "org".into()
55}
56
57/// Request to search knowledge.
58#[derive(Debug, Deserialize)]
59pub struct SearchRequest {
60    pub query: String,
61    #[serde(default = "default_limit")]
62    pub limit: usize,
63    #[serde(default)]
64    pub org_id: Option<String>,
65    #[serde(default)]
66    pub source_type: Option<String>,
67    #[serde(default)]
68    pub project_id: Option<String>,
69    /// Minimum score threshold (0.0-1.0). Results below this are discarded.
70    #[serde(default = "default_min_score")]
71    pub min_score: f64,
72    /// If true, include public entries from all orgs (cross-org federation).
73    #[serde(default)]
74    pub federated: bool,
75}
76
77fn default_limit() -> usize {
78    5
79}
80
81fn default_min_score() -> f64 {
82    0.3
83}
84
85/// Stats about the knowledge store.
86#[derive(Debug, Serialize)]
87pub struct StoreStats {
88    pub total_entries: i64,
89    pub total_by_source: Vec<(String, i64)>,
90    pub embedding_dimensions: usize,
91}