IPFRS Node.js Bindings
Node.js/TypeScript bindings for IPFRS (Inter-Planetary File Rust System) - a content-addressed storage system with semantic search and logic programming capabilities.
Features
- Content-Addressed Storage: Store and retrieve data using cryptographic content identifiers (CIDs)
- Semantic Search: Vector similarity search with HNSW indexing
- Logic Programming: TensorLogic inference engine with backward chaining
- Persistence: Save and load indexes and knowledge bases
- Promise-based API: Full async/await support
- TypeScript: Complete type definitions included
Installation
# or
Quick Start
Basic Block Operations
const = require;
.;
TypeScript Example
import { Node, NodeConfig, SearchResult } from '@ipfrs/core';
async function semanticSearch() {
const config: NodeConfig = {
storagePath: '/tmp/ipfrs-semantic',
enableSemantic: true,
enableTensorlogic: false
};
const node = new Node(config);
await node.start();
// Store content with embeddings
const embeddingDim = 128;
for (let i = 0; i < 10; i++) {
const data = Buffer.from(`Document ${i}`);
const cid = await node.putBlock(data);
// Generate random embedding (in real use, use a model)
const embedding = Array.from({ length: embeddingDim }, () => Math.random());
await node.indexContent(cid, embedding);
}
// Search for similar content
const query = Array.from({ length: embeddingDim }, () => Math.random());
const results: SearchResult[] = await node.searchSimilar(query, 5);
console.log('Search results:');
for (const result of results) {
console.log(` CID: ${result.cid}, Score: ${result.score.toFixed(4)}`);
}
await node.stop();
}
semanticSearch().catch(console.error);
Logic Programming
const = require;
.;
Persistence
const = require;
.;
API Reference
Node
The main interface for all IPFRS operations.
Constructor:
new Node(config?: NodeConfig)- Create a new IPFRS node
Methods:
Lifecycle:
start(): Promise<void>- Start the nodestop(): Promise<void>- Stop the node
Block Operations:
putBlock(data: Buffer): Promise<string>- Store a block, returns CIDgetBlock(cid: string): Promise<Buffer | null>- Retrieve a blockhasBlock(cid: string): Promise<boolean>- Check block existencedeleteBlock(cid: string): Promise<void>- Delete a block
Semantic Search:
indexContent(cid: string, embedding: number[]): Promise<void>- Index for semantic searchsearchSimilar(query: number[], k: number): Promise<SearchResult[]>- Search similar contentsearchFiltered(query: number[], k: number, filter?: QueryFilter): Promise<SearchResult[]>- Search with filters
Logic Programming:
addFact(fact: Predicate): void- Add a factaddRule(rule: Rule): void- Add a ruleinfer(goal: Predicate): string[]- Run inferenceprove(goal: Predicate): string | null- Generate proofkbStats(): KbStats- Get KB statistics
Persistence:
saveSemanticIndex(path: string): Promise<void>- Save semantic indexloadSemanticIndex(path: string): Promise<void>- Load semantic indexsaveKb(path: string): Promise<void>- Save knowledge baseloadKb(path: string): Promise<void>- Load knowledge base
Types
NodeConfig:
interface NodeConfig {
storagePath?: string;
enableSemantic?: boolean;
enableTensorlogic?: boolean;
}
SearchResult:
interface SearchResult {
cid: string;
score: number;
}
QueryFilter:
interface QueryFilter {
minScore?: number;
maxScore?: number;
maxResults?: number;
cidPrefix?: string;
}
Term:
interface Term {
kind: 'int' | 'float' | 'string' | 'bool' | 'var';
value: string;
}
Predicate:
interface Predicate {
name: string;
args: Term[];
}
Rule:
interface Rule {
head: Predicate;
body: Predicate[];
}
KbStats:
interface KbStats {
numFacts: number;
numRules: number;
}
Building from Source
# Install dependencies
# Build debug version
# Build release version
# Run tests
Requirements
- Node.js 14+
- Rust 1.70+ (for building from source)
License
Apache-2.0