SemanticIndex.h header
#include <ew/app/SemanticIndex.h>
Namespace ew::app
Entry struct
struct ew::app::Entry
One indexed content object and its embedding.
Members
ew::core::ContentId ew::app::SemanticIndex::Entry::id
The indexed content object.
std::vector<float> ew::app::SemanticIndex::Entry::vector
Its stored embedding vector.
SemanticIndex class
class ew::app::SemanticIndex
An in-memory vector index over content embeddings for semantic (meaning-based) retrieval: add an embedding per content object, then search returns the closest ids by cosine similarity. This is the core of canon-aware AI retrieval (RAG) – ground an AI request on the handful of Codex entities most relevant to a query even when the whole codex would overflow the model's context. Provider-agnostic (fed by whatever embeddings endpoint the user configures); a linear scan, which is ample for a project's entities; not thread-safe.
Members
void ew::app::SemanticIndex::add(ew::core::ContentId id, std::vector< float > vector)
Adds vector for id, replacing any existing entry for that id. A null id or an empty vector is ignored.
void ew::app::SemanticIndex::remove(ew::core::ContentId id)
Removes the entry for id if present.
void ew::app::SemanticIndex::clear()
Drops all entries.
std::size_t ew::app::SemanticIndex::size() const
The number of indexed entries.
bool ew::app::SemanticIndex::contains(ew::core::ContentId id) const
True when id has an entry.
std::vector< ew::core::ContentId > ew::app::SemanticIndex::ids() const
The ids currently indexed, in insertion order (useful for spotting what still needs embedding, or what has gone stale).
std::vector< float > ew::app::SemanticIndex::vectorFor(ew::core::ContentId id) const
The stored embedding for id, or an empty vector when id is not indexed. Lets a caller find items similar to an already-indexed one without re-embedding it (feed the result to search).
std::vector< SemanticMatch > ew::app::SemanticIndex::search(const std::vector< float > &query, int topK) const
The topK entries most similar to query by cosine similarity, most-similar first. Zero-similarity (unrelated) entries are skipped, so an off-topic query returns fewer – or no – results. Returns empty when query is empty or topK is not positive.
SemanticMatch struct
struct ew::app::SemanticMatch
One retrieval result: the matched content id and its cosine similarity to the query (higher is closer). Results are returned ranked most-similar first.
Members
ew::core::ContentId ew::app::SemanticMatch::id
The matched content object.
float ew::app::SemanticMatch::score = 0.0F
Cosine similarity of its embedding to the query, in (0, 1].
bool operator==(const SemanticMatch &, const SemanticMatch &)=default
Matches compare equal when both fields match.