Skip to main content

Self-aware vector embeddings with temporal awareness, confidence decay, and relational intelligence for RAG systems

Project description

SmartVector

Self-aware vector embeddings for RAG systems that know what they mean, when they're valid, how confident they should be, and who they're related to.

Python 3.10+ License: MIT Tests


The Problem

Traditional RAG systems treat every vector embedding as equal — a fact from an authoritative database and a rumor from Slack get the same treatment. When documents are updated, old chunks linger in the vector store with no way to know they're outdated. When two sources contradict each other, the system has no mechanism to prefer one over the other.

SmartVector solves this by giving each vector three properties that traditional embeddings lack:

  1. Temporal Awareness — vectors know when they were created, when they expire, and how their relevance decays over time
  2. Confidence Decay — vectors carry a trust score derived from source authority, user feedback, and age, modeled on the Ebbinghaus forgetting curve
  3. Relational Awareness — vectors form a knowledge graph with dependency edges, enabling ripple propagation when upstream facts change

Installation

pip install smartvector

Or install from source:

git clone https://github.com/xunaizhong/smartvector.git
cd smartvector
pip install -e ".[dev]"

Quick Start

from smartvector import SmartVectorDB

db = SmartVectorDB()

# Ingest a document (vectors start as UNCONSOLIDATED)
db.ingest_document(
    doc_id="api-spec", version=1,
    text="The API rate limit is 1000 requests per second.",
    source_name="api_docs", source_type="technical_doc",
    author="alice", authority=0.85,
)

# Run consolidation (like the brain's sleep cycle)
db.run_consolidation()

# Query with 4-signal scoring
results = db.query("What is the rate limit?", top_k=3)
print(results[0].vector.content)
# → "The API rate limit is 1000 requests per second."
print(results[0].final_score)
# → 0.7523 (similarity + temporal + confidence + relational)

# Surgical update — only affected chunks are replaced
db.ingest_update(
    doc_id="api-spec",
    old_text="The API rate limit is 1000 requests per second.",
    new_text="The API rate limit is 2000 requests per second.",
    source_name="api_docs", source_type="technical_doc",
    author="alice_v2", authority=0.90,
)

# Old vectors are DEPRECATED, new ones take over
results = db.query("What is the rate limit?", top_k=1)
print(results[0].vector.content)
# → "The API rate limit is 2000 requests per second."

Architecture

┌─────────────────────────────────────────────────────────┐
│                    SmartVectorDB                         │
│                                                          │
│  ┌────────────┐  ┌────────────────┐  ┌───────────────┐ │
│  │ Vector     │  │ Confidence     │  │ Consolidation │ │
│  │ Store      │──│ Engine         │──│ Agent         │ │
│  └────────────┘  └────────────────┘  └───────────────┘ │
│       │                │                    │            │
│  ┌────────────┐  ┌────────────────┐  ┌───────────────┐ │
│  │ Temporal   │  │ 4-Signal       │  │ Ripple        │ │
│  │ Scorer     │──│ Retrieval      │──│ Propagator    │ │
│  └────────────┘  └────────────────┘  └───────────────┘ │
└─────────────────────────────────────────────────────────┘

4-Signal Retrieval Scoring

final = 0.35 × similarity
      + 0.25 × temporal_score
      + 0.25 × confidence
      + 0.15 × relational_bonus

Each signal is configurable. In production, replace the keyword similarity with embedding cosine similarity.

5 Lifecycle Stages (Neuroscience-Inspired)

Stage Name Analogy What Happens
1 Encoding Hippocampal fast-write Document ingested, vectors created as UNCONSOLIDATED
2 Consolidation Sleep-time replay Background agent builds relationships, detects conflicts
3 Retrieval Memory recall 4-signal scoring, user feedback reinforces confidence
4 Update Schema revision Surgical diff, ripple propagation through knowledge graph
5 Decay Forgetting curve Confidence decays exponentially, low-trust → DORMANT

Key Components

SmartVector

The fundamental unit — a dataclass carrying content, temporal metadata, confidence signals, and graph edges.

ConfidenceEngine

Manages the trust lifecycle: exponential decay (C(t) = C₀ × 2^(-t/half_life)), feedback adjustment, and access reinforcement.

ConsolidationAgent

The "sleep-time" background process that detects conflicts, builds relationship edges, and propagates ripples when facts change.

SmartVectorDB

The complete database combining ingestion, consolidation, 4-signal retrieval, surgical updates, and LLM context building.

Source Authority Hierarchy

Source Type Default Confidence
Official DB (CRM, ERP) 0.95
Policy Documents 0.90
Technical Docs 0.85
Wiki / Confluence 0.75
Email 0.50
Meeting Notes 0.45
Slack Messages 0.30
Unknown 0.20

Examples

Run the built-in demo:

smartvector demo

Or run individual examples:

python examples/quickstart.py
python examples/conflict_resolution.py

Testing

pip install -e ".[dev]"
pytest tests/ -v

63 tests covering all components: models, confidence engine, conflict detection, ripple propagation, surgical updates, and full lifecycle.

Theory & Research

SmartVector draws from:

  • Neuroscience: Hippocampal-neocortical memory consolidation, Ebbinghaus forgetting curve, memory reconsolidation
  • Temporal Knowledge Graphs: DE-SimplE, ATiSE, PTBox — time-aware embeddings
  • MAGMA Architecture: Dual-stream (fast ingestion + slow consolidation)
  • GNN Message Passing: Ripple propagation through knowledge graphs
  • VersionRAG: 90% accuracy on versioned queries vs 58% standard RAG

See docs/theory_visual.html for the full interactive proposal with implementation details.

Roadmap

Phase 1 (Current): Core data structures, confidence engine, consolidation agent, keyword-based retrieval, surgical updates, CLI demo.

Phase 2 (Next): Real embedding integration (sentence-transformers), persistent storage (SQLite/Postgres), NLI-based conflict detection, REST API.

Phase 3 (Future): Distributed consolidation, real-time streaming ingestion, Matryoshka adaptive embeddings, production integrations (LangChain, LlamaIndex).

Contributing

Contributions are welcome! Please open an issue first to discuss what you'd like to change.

  1. Fork the repo
  2. Create a feature branch (git checkout -b feature/amazing-thing)
  3. Make your changes with tests
  4. Run pytest tests/ -v to verify
  5. Open a Pull Request

License

MIT — see LICENSE for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

smartvector_rag-0.1.0.tar.gz (27.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

smartvector_rag-0.1.0-py3-none-any.whl (23.8 kB view details)

Uploaded Python 3

File details

Details for the file smartvector_rag-0.1.0.tar.gz.

File metadata

  • Download URL: smartvector_rag-0.1.0.tar.gz
  • Upload date:
  • Size: 27.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for smartvector_rag-0.1.0.tar.gz
Algorithm Hash digest
SHA256 86300399f97a2fdffac136eab02a113dec6fcb4f762d59488ec1554bb8b250b7
MD5 b8332e111e1c929f432b02141bfa0aef
BLAKE2b-256 55ac358326c0f278ad5c5f47e1ce38c44368de94b46c2b1d5c31515ef1c5c466

See more details on using hashes here.

File details

Details for the file smartvector_rag-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for smartvector_rag-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e74ef93c593c2eddc29782e3d7a6f81380f222e7c69f81b125605339db3ae6d8
MD5 12a2a0e9c0db45ecc536119a740c1918
BLAKE2b-256 4a95e0484cd3054c45831fc48dd3d60e52443509c1a756669e7b80db1036be3d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page