nimgent/vector_store
This page is generated from the module’s exported API and ## documentation comments.
Small in-memory vector store for local retrieval and examples.
VectorRecord
Section titled “VectorRecord”Stored vector and metadata identified by a caller-provided ID.
VectorRecord = object id*: string embedding*: seq[float] metadata*: JsonNodeVectorMatch
Section titled “VectorMatch”Vector search result with its similarity score.
VectorMatch = object id*: string score*: float metadata*: JsonNodeInMemoryVectorStore
Section titled “InMemoryVectorStore”Small in-memory vector store for local retrieval and tests.
InMemoryVectorStore = ref objectProcedures
Section titled “Procedures”cosineSimilarity
Section titled “cosineSimilarity”Cosine similarity in [-1, 1]. Both vectors must be non-empty and equal-sized.
proc cosineSimilarity(a, b: openArray[float]): float {.raises: [ValueError], tags: [], forbids: [].}Returns: float.
Arguments
Section titled “Arguments”| Name | Type | Default |
|---|---|---|
a |
openArray[float] |
|
b |
openArray[float] |
newInMemoryVectorStore
Section titled “newInMemoryVectorStore”Create an empty in-memory vector store.
proc newInMemoryVectorStore(): InMemoryVectorStore {.raises: [], tags: [], forbids: [].}Returns: InMemoryVectorStore.
upsert
Section titled “upsert”Insert or replace a vector by ID.
proc upsert(store: InMemoryVectorStore; id: string; embedding: openArray[float]; metadata: JsonNode = nil) {.raises: [ValueError], tags: [], forbids: [].}Arguments
Section titled “Arguments”| Name | Type | Default |
|---|---|---|
store |
InMemoryVectorStore |
|
id |
string |
|
embedding |
openArray[float] |
|
metadata |
JsonNode |
nil |
delete
Section titled “delete”Delete a vector by ID and report whether it existed.
proc delete(store: InMemoryVectorStore; id: string): bool {. raises: [ValueError], tags: [], forbids: [].}Returns: bool.
Arguments
Section titled “Arguments”| Name | Type | Default |
|---|---|---|
store |
InMemoryVectorStore |
|
id |
string |
search
Section titled “search”Return up to limit vectors ranked by cosine similarity.
proc search(store: InMemoryVectorStore; embedding: openArray[float]; limit = 10): seq[ VectorMatch] {.raises: [ValueError], tags: [], forbids: [].}Returns: seq[VectorMatch].
Arguments
Section titled “Arguments”| Name | Type | Default |
|---|---|---|
store |
InMemoryVectorStore |
|
embedding |
openArray[float] |
|
limit |
inferred |
10 |
Save the store as a readable, versioned JSON document.
proc save(store: InMemoryVectorStore; path: string) {. raises: [IOError, ValueError, KeyError], tags: [WriteIOEffect], forbids: [].}Arguments
Section titled “Arguments”| Name | Type | Default |
|---|---|---|
store |
InMemoryVectorStore |
|
path |
string |
loadInMemoryVectorStore
Section titled “loadInMemoryVectorStore”Load a store saved by save.
proc loadInMemoryVectorStore(path: string): InMemoryVectorStore {. raises: [IOError, ValueError, KeyError, ValueError], tags: [ReadIOEffect, WriteIOEffect], forbids: [].}Returns: InMemoryVectorStore.
Arguments
Section titled “Arguments”| Name | Type | Default |
|---|---|---|
path |
string |