Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
283 changes: 111 additions & 172 deletions go/engine_native.go

Large diffs are not rendered by default.

Binary file modified go/lib/darwin_amd64/libcstx_ffi.a
Binary file not shown.
Binary file modified go/lib/darwin_arm64/libcstx_ffi.a
Binary file not shown.
Binary file modified go/lib/linux_amd64/libcstx_ffi.a
Binary file not shown.
Binary file modified go/lib/linux_arm64/libcstx_ffi.a
Binary file not shown.
Binary file modified go/lib/windows_amd64/libcstx_ffi.a
Binary file not shown.
153 changes: 0 additions & 153 deletions go/proto_native.go

This file was deleted.

40 changes: 4 additions & 36 deletions go/rag_native.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,34 +71,18 @@ func (s *nativeRagIndexSession) metadata(_ context.Context) (*cstxproto.RagIndex
if s.session == nil {
return nil, s.closedError("graph.rag.index.metadata")
}
data, err := bufferResult("graph.rag.index.metadata", func(out, errBuf *C.CstxBuffer) C.CstxStatusCode {
return protoResult[cstxproto.RagIndexResult]("graph.rag.index.metadata", func(out, errBuf *C.CstxBuffer) C.CstxStatusCode {
return C.cstx_rag_index_session_metadata(s.session, out, errBuf)
})
if err != nil {
return nil, err
}
var result cstxproto.RagIndexResult
if err := proto.Unmarshal(data, &result); err != nil {
return nil, fmt.Errorf("cstx: decode rag index result protobuf: %w", err)
}
return &result, nil
}

func (s *nativeRagIndexSession) pending(_ context.Context, offset, limit int) (*cstxproto.RagRecordPage, error) {
if s.session == nil {
return nil, s.closedError("graph.rag.index.pending")
}
data, err := bufferResult("graph.rag.index.pending", func(out, errBuf *C.CstxBuffer) C.CstxStatusCode {
return protoResult[cstxproto.RagRecordPage]("graph.rag.index.pending", func(out, errBuf *C.CstxBuffer) C.CstxStatusCode {
return C.cstx_rag_index_session_pending(s.session, C.size_t(offset), C.size_t(limit), out, errBuf)
})
if err != nil {
return nil, err
}
var page cstxproto.RagRecordPage
if err := proto.Unmarshal(data, &page); err != nil {
return nil, fmt.Errorf("cstx: decode rag record page protobuf: %w", err)
}
return &page, nil
}

func (s *nativeRagIndexSession) deletes(_ context.Context) ([]string, error) {
Expand Down Expand Up @@ -198,17 +182,9 @@ func (r *nativeRagRetrieval) requests(_ context.Context) (*cstxproto.RecallPlan,
if r.retrieval == nil {
return nil, &Error{Code: CodeNotInitialized, Operation: "graph.rag.retrieve.requests", Message: "retrieval is closed"}
}
data, err := bufferResult("graph.rag.retrieve.requests", func(out, errBuf *C.CstxBuffer) C.CstxStatusCode {
return protoResult[cstxproto.RecallPlan]("graph.rag.retrieve.requests", func(out, errBuf *C.CstxBuffer) C.CstxStatusCode {
return C.cstx_rag_retrieval_requests(r.retrieval, out, errBuf)
})
if err != nil {
return nil, err
}
var plan cstxproto.RecallPlan
if err := proto.Unmarshal(data, &plan); err != nil {
return nil, fmt.Errorf("cstx: decode recall plan protobuf: %w", err)
}
return &plan, nil
}

func (r *nativeRagRetrieval) complete(_ context.Context, results *cstxproto.RecallResults) (*cstxproto.RagResult, error) {
Expand All @@ -219,19 +195,11 @@ func (r *nativeRagRetrieval) complete(_ context.Context, results *cstxproto.Reca
if err != nil {
return nil, err
}
data, err := bufferResult("graph.rag.complete", func(out, errBuf *C.CstxBuffer) C.CstxStatusCode {
return protoResult[cstxproto.RagResult]("graph.rag.complete", func(out, errBuf *C.CstxBuffer) C.CstxStatusCode {
rc := C.cstx_rag_retrieval_complete(r.retrieval, byteSlice(payload), out, errBuf)
runtime.KeepAlive(payload)
return rc
})
if err != nil {
return nil, err
}
var result cstxproto.RagResult
if err := proto.Unmarshal(data, &result); err != nil {
return nil, fmt.Errorf("cstx: decode rag result protobuf: %w", err)
}
return &result, nil
}

func (r *nativeRagRetrieval) close() {
Expand Down
5 changes: 5 additions & 0 deletions ts/wasm/cstx_wasm.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ export class Graph {
nodeCount(): bigint;
nodeTypes(): any;
nodes(options?: any | null): GraphCursor;
/**
* Parse one extension artifact without mutating this graph.
*/
parse(plugin: string, artifact: string, data: Uint8Array): any;
patchNodeAnnotations(node_ids: string[] | null | undefined, patch: any): bigint;
query(expression: string, options?: any | null): GraphCursor;
querySubgraph(expression: string, limit?: number | null, page?: number | null, exclude_mask?: bigint | null, include_mask?: bigint | null): CSTX;
Expand Down Expand Up @@ -118,6 +122,7 @@ export interface InitOutput {
readonly extensions_schemas: (a: number, b: number) => void;
readonly extensions_parsesArtifact: (a: number, b: number, c: number, d: number) => void;
readonly extensions_anchorConcepts: (a: number, b: number) => void;
readonly graph_parse: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number) => void;
readonly graph_addNode: (a: number, b: number, c: number) => void;
readonly graph_addNodes: (a: number, b: number, c: number) => void;
readonly graph_addRelationships: (a: number, b: number, c: number) => void;
Expand Down
35 changes: 35 additions & 0 deletions ts/wasm/cstx_wasm.js
Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,34 @@ export class Graph {
wasm.__wbindgen_add_to_stack_pointer(16);
}
}
/**
* Parse one extension artifact without mutating this graph.
* @param {string} plugin
* @param {string} artifact
* @param {Uint8Array} data
* @returns {any}
*/
parse(plugin, artifact, data) {
try {
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
const ptr0 = passStringToWasm0(plugin, wasm.__wbindgen_export, wasm.__wbindgen_export2);
const len0 = WASM_VECTOR_LEN;
const ptr1 = passStringToWasm0(artifact, wasm.__wbindgen_export, wasm.__wbindgen_export2);
const len1 = WASM_VECTOR_LEN;
const ptr2 = passArray8ToWasm0(data, wasm.__wbindgen_export);
const len2 = WASM_VECTOR_LEN;
wasm.graph_parse(retptr, this.__wbg_ptr, ptr0, len0, ptr1, len1, ptr2, len2);
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
if (r2) {
throw takeObject(r1);
}
return takeObject(r0);
} finally {
wasm.__wbindgen_add_to_stack_pointer(16);
}
}
/**
* @param {string[] | null | undefined} node_ids
* @param {any} patch
Expand Down Expand Up @@ -1750,6 +1778,13 @@ function isLikeNone(x) {
return x === undefined || x === null;
}

function passArray8ToWasm0(arg, malloc) {
const ptr = malloc(arg.length * 1, 1) >>> 0;
getUint8ArrayMemory0().set(arg, ptr / 1);
WASM_VECTOR_LEN = arg.length;
return ptr;
}

function passArrayJsValueToWasm0(array, malloc) {
const ptr = malloc(array.length * 4, 4) >>> 0;
const mem = getDataViewMemory0();
Expand Down
Binary file modified ts/wasm/cstx_wasm_bg.wasm
Binary file not shown.
1 change: 1 addition & 0 deletions ts/wasm/cstx_wasm_bg.wasm.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export const extensions_schema: (a: number, b: number, c: number, d: number) =>
export const extensions_schemas: (a: number, b: number) => void;
export const extensions_parsesArtifact: (a: number, b: number, c: number, d: number) => void;
export const extensions_anchorConcepts: (a: number, b: number) => void;
export const graph_parse: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number) => void;
export const graph_addNode: (a: number, b: number, c: number) => void;
export const graph_addNodes: (a: number, b: number, c: number) => void;
export const graph_addRelationships: (a: number, b: number, c: number) => void;
Expand Down
Loading