Class MibEmbeddingIndex
java.lang.Object
org.snmp4j.mcp.tool.mib.semantic.MibEmbeddingIndex
In-memory vector index over MIB objects with cosine-similarity search and
optional GZIP'd JSON persistence.
Each MIB object's DESCRIPTION is split into one or more paragraph-aligned chunks
by the MibChunkFormatter, and each chunk is embedded and indexed independently.
Search results are deduplicated to one hit per object, keeping the best-scoring chunk.
Usage pattern (lazy build):
index.buildAsync(smiManager, embeddingClient, formatter, cachePath); // later … List<SearchResult> hits = index.search(queryVector, 10, null);
- Since:
- 1.0.0
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordMetadata stored for each indexed chunk.static final recordA single search hit with its cosine-similarity score. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidbuild(com.snmp4j.smi.SmiManager smiManager, EmbeddingClient client, MibChunkFormatter formatter) Builds the index synchronously by embedding all chunks of every object returned bysmiManager.findSmiObject(null, ACCEPT_ALL).voidcopyFrom(MibEmbeddingIndex source) Replaces all content of this index with the content ofsource.Returns the embedding model ID that was active when the index was built or loaded.booleanisEmpty()Checks if the index contains no chunks.static MibEmbeddingIndexLoads a previously saved index from a GZIP'd JSON file.voidRemoves all chunk entries for the given OID, if present.voidSaves the index to a GZIP'd JSON file atpath.Searches the index by cosine similarity toqueryVector.intsize()Returns the number of indexed chunks.voidupsert(com.snmp4j.smi.SmiObject obj, EmbeddingClient client, MibChunkFormatter formatter) Incrementally upserts (adds or replaces) a single object and all of its chunks.
-
Constructor Details
-
MibEmbeddingIndex
public MibEmbeddingIndex()Creates a new, empty embedding index.
-
-
Method Details
-
build
public void build(com.snmp4j.smi.SmiManager smiManager, EmbeddingClient client, MibChunkFormatter formatter) throws IOException Builds the index synchronously by embedding all chunks of every object returned bysmiManager.findSmiObject(null, ACCEPT_ALL).Clears any previously indexed content first.
- Parameters:
smiManager- source of MIB objectsclient- embedding backendformatter- splits SmiObjects into one or more text chunks- Throws:
IOException- if the embedding client reports an error
-
upsert
public void upsert(com.snmp4j.smi.SmiObject obj, EmbeddingClient client, MibChunkFormatter formatter) throws IOException Incrementally upserts (adds or replaces) a single object and all of its chunks.- Parameters:
obj- the MIB object to indexclient- embedding backend used to generate the vectorsformatter- splits the object into one or more embeddable text chunks- Throws:
IOException- if the embedding client reports a transport or API error
-
remove
Removes all chunk entries for the given OID, if present.- Parameters:
oid- dotted-decimal OID string key to remove
-
search
public List<MibEmbeddingIndex.SearchResult> search(float[] queryVector, int limit, String typeFilter, String syntaxFilter) Searches the index by cosine similarity toqueryVector.When an object has multiple chunks, only its best-scoring chunk contributes one result; the response contains at most one entry per OID.
- Parameters:
queryVector- pre-embedded querylimit- maximum number of results (clamped to 1..1000)typeFilter- optional SmiType name substring filter, e.g. "OBJECT_TYPE"syntaxFilter- optional SmiSyntax name substring filter, e.g. "OBJECT IDENTIFIER"- Returns:
- results sorted by descending score, one per OID
-
save
Saves the index to a GZIP'd JSON file atpath. The file can be reloaded withload(Path).- Parameters:
path- destination file path- Throws:
IOException- if the file cannot be written
-
load
Loads a previously saved index from a GZIP'd JSON file. Both the legacy1.0(one entry per OID) and the current chunked format are accepted.- Parameters:
path- the file written bysave(Path)- Returns:
- a populated index (the caller should verify modelId matches the current client)
- Throws:
IOException- if the file cannot be read or parsed
-
size
public int size()Returns the number of indexed chunks.- Returns:
- number of indexed chunks (an object may contribute more than one)
-
isEmpty
public boolean isEmpty()Checks if the index contains no chunks.- Returns:
trueif the index contains no chunks
-
getModelId
Returns the embedding model ID that was active when the index was built or loaded.- Returns:
- model identifier string, or an empty string if unknown
-
copyFrom
Replaces all content of this index with the content ofsource. Used to update the live-shared instance from a freshly loaded or rebuilt index.- Parameters:
source- the index whose data should be copied into this instance
-