Skip to main content

MossClient

Local semantic search client for vector similarity operations.

Quick Example

const client = new MossClient('your-project-id', 'your-project-key');

// Create an index with documents
await client.createIndex('docs', [
  { id: '1', text: 'Machine learning fundamentals' },
  { id: '2', text: 'Deep learning neural networks' }
], 'moss-minilm');

// Query the index
const results = await client.query('docs', 'AI and neural networks');

Constructor

new MossClient()

new MossClient(projectId: string, projectKey: string): MossClient
Creates a new MossClient instance for local operations. Parameters
NameTypeRequiredDescription
projectIdstringYesYour project identifier.
projectKeystringYesYour project authentication key.
Returns MossClient

Methods

createIndex()

createIndex(indexName: string, docs: DocumentInfo[], modelId: string): Promise<boolean>
Creates a new index with the provided documents. Parameters
NameTypeRequiredDescription
indexNamestringYesName of the index to create.
docsDocumentInfo[]YesInitial documents to add to the index.
modelIdstringYesModel to use for embeddings.
Returns Promise<boolean> - Promise that resolves to true if successful. Throws If the index already exists or creation fails. Example
const success = await client.createIndex('knowledge-base', [
  { id: 'doc1', text: 'Introduction to AI' },
  { id: 'doc2', text: 'Machine learning basics' }
], 'moss-minilm');

getIndex()

getIndex(indexName: string): Promise<IndexInfo>
Gets information about a specific index. Parameters
NameTypeRequiredDescription
indexNamestringYesName of the index to retrieve.
Returns Promise<IndexInfo> - Promise that resolves to IndexInfo object. Throws If the index does not exist. Example
const info = await client.getIndex('knowledge-base');
console.log(`Index has ${info.docCount} documents`);

listIndexes()

listIndexes(): Promise<IndexInfo[]>
Lists all available indexes. Returns Promise<IndexInfo[]> - Promise that resolves to array of IndexInfo objects. Example
const indexes = await client.listIndexes();
indexes.forEach(index => {
  console.log(`${index.name}: ${index.docCount} docs`);
});

deleteIndex()

deleteIndex(indexName: string): Promise<boolean>
Deletes an index and all its data. Parameters
NameTypeRequiredDescription
indexNamestringYesName of the index to delete.
Returns Promise<boolean> - Promise that resolves to true if successful. Throws If the index does not exist. Example
const deleted = await client.deleteIndex('old-index');

loadIndex()

loadIndex(indexName: string): Promise<string>
Loads an index from a local .moss file. Parameters
NameTypeRequiredDescription
indexNamestringYesName of the index to load.
Returns Promise<string> - Promise that resolves to the index name. Throws If the index file does not exist or is invalid. Example
const indexName = await client.loadIndex('my-index');
console.log(`Loaded index: ${indexName}`);

addDocs()

addDocs(indexName: string, docs: DocumentInfo[], options?: AddDocumentsOptions): Promise<{ added: number; updated: number; }>
Adds or updates documents in an index. Parameters
NameTypeRequiredDescription
indexNamestringYesName of the target index.
docsDocumentInfo[]YesDocuments to add or update.
optionsAddDocumentsOptionsNoOptional configuration for the operation.
Returns Promise<{ added: number; updated: number; }> - Promise that resolves to operation result with counts. Throws If the index does not exist. Example
const result = await client.addDocs('knowledge-base', [
  { id: 'new-doc', text: 'New content to index' }
], { upsert: true });
console.log(`Added: ${result.added}, Updated: ${result.updated}`);

deleteDocs()

deleteDocs(indexName: string, docIds: string[]): Promise<{ deleted: number; }>
Deletes documents from an index by their IDs. Parameters
NameTypeRequiredDescription
indexNamestringYesName of the target index.
docIdsstring[]YesArray of document IDs to delete.
Returns Promise<{ deleted: number; }> - Promise that resolves to operation result with count. Throws If the index does not exist. Example
const result = await client.deleteDocs('knowledge-base', ['doc1', 'doc2']);
console.log(`Deleted ${result.deleted} documents`);

getDocs()

getDocs(indexName: string, options?: GetDocumentsOptions): Promise<DocumentInfo[]>
Retrieves documents from an index. Parameters
NameTypeRequiredDescription
indexNamestringYesName of the target index.
optionsGetDocumentsOptionsNoOptional configuration for retrieval.
Returns Promise<DocumentInfo[]> - Promise that resolves to array of documents. Throws If the index does not exist. Example
// Get all documents
const allDocs = await client.getDocs('knowledge-base');

// Get specific documents
const specificDocs = await client.getDocs('knowledge-base', {
  docIds: ['doc1', 'doc2']
});

query()

query(indexName: string, query: string, topK?: number): Promise<SearchResult>
Performs a semantic similarity search against the specified index. Parameters
NameTypeRequiredDefaultDescription
indexNamestringYes-Name of the target index to search.
querystringYes-The search query text.
topKnumberNo5Maximum number of results to return.
Returns Promise<SearchResult> - Promise that resolves to SearchResult with matching documents. Throws If the specified index does not exist. Example
const results = await client.query('knowledge-base', 'machine learning');
results.docs.forEach(doc => {
  console.log(`${doc.id}: ${doc.text} (score: ${doc.score})`);
});