-
Notifications
You must be signed in to change notification settings - Fork 274
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a5349e4
commit c72cb30
Showing
21 changed files
with
804 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -167,3 +167,8 @@ cython_debug/ | |
# local scratch pad | ||
scratch.sql | ||
scratch.py | ||
|
||
# Some SDK specific things | ||
expanded.rs | ||
test | ||
pgml.h |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
BINARY_NAME=pgml | ||
|
||
build: | ||
cargo build --features c | ||
cargo expand --features c > expanded.rs | ||
cbindgen --lang C -o pgml.h expanded.rs | ||
# GOARCH=amd64 GOOS=darwin go build -o ${BINARY_NAME}-darwin main.go | ||
GOARCH=amd64 GOOS=linux go build -o ${BINARY_NAME}-linux pgml.go | ||
# GOARCH=amd64 GOOS=windows go build -o ${BINARY_NAME}-windows main.go | ||
|
||
build_test: | ||
cargo build --features c | ||
cargo expand --features c > expanded.rs | ||
cbindgen --lang C -o pgml.h expanded.rs | ||
gcc test.c -o test -l pgml -L ./../target/debug | ||
|
||
test: build_test | ||
LD_LIBRARY_PATH=./../target/debug ./test | ||
|
||
test_c: | ||
gcc test.c -o test -l pgml -L ./../target/debug | ||
LD_LIBRARY_PATH=./../target/debug ./test | ||
|
||
run: build | ||
LD_LIBRARY_PATH=./../target/debug ./${BINARY_NAME}-linux | ||
|
||
clean: | ||
go clean | ||
# rm ${BINARY_NAME}-darwin | ||
rm ${BINARY_NAME}-linux | ||
# rm ${BINARY_NAME}-windows |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module pgml | ||
|
||
go 1.22.2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package main | ||
|
||
/* | ||
#cgo LDFLAGS: -l pgml -L ./../target/debug | ||
#include "pgml.h" | ||
*/ | ||
import "C" | ||
|
||
import ( | ||
"unsafe" | ||
) | ||
|
||
type Collection struct { | ||
collection *C.CollectionC | ||
} | ||
|
||
func main() { | ||
c_string_p := C.CString("Test CString") | ||
defer C.free(unsafe.Pointer(c_string_p)) | ||
collection := C.new_collection(c_string_p) | ||
C.test_collection(collection) | ||
defer C.free_collection(collection) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#include <stdio.h> | ||
|
||
#include "pgml.h" | ||
|
||
int main() { | ||
// Create the Collection and Pipeline | ||
CollectionC * collection = CollectionC_new("test_c", NULL); | ||
PipelineC * pipeline = PipelineC_new("test_c", "{\"text\": {\"splitter\": {\"model\": \"recursive_character\"},\"semantic_search\": {\"model\": \"intfloat/e5-small\"}}}"); | ||
|
||
// Add the Pipeline to the Collection | ||
CollectionC_add_pipeline(collection, pipeline); | ||
|
||
// Upsert the documents | ||
char * documents_to_upsert[2] = {"{\"id\": \"doc1\", \"text\": \"test1\"}", "{\"id\": \"doc2\", \"text\": \"test2\"}"}; | ||
CollectionC_upsert_documents(collection, documents_to_upsert, 2, NULL); | ||
|
||
// Retrieve the documents | ||
unsigned long r_size = 0; | ||
char** documents = CollectionC_get_documents(collection, NULL, &r_size); | ||
|
||
// Print the documents | ||
printf("\n\nPrinting documents:\n"); | ||
int i; | ||
for (i = 0; i < r_size; i++) { | ||
printf("Document %u -> %s\n", i, documents[i]); | ||
} | ||
|
||
// Search over the documents | ||
r_size = 0; | ||
char** results = CollectionC_vector_search(collection, "{\"query\": {\"fields\": {\"text\": {\"query\": \"Test query!\"}}}, \"limit\": 5}", pipeline, &r_size); | ||
printf("\n\nPrinting results:\n"); | ||
for (i = 0; i < r_size; i++) { | ||
printf("Result %u -> %s\n", i, results[i]); | ||
} | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
use crate::types::{DateTime, GeneralJsonAsyncIterator, GeneralJsonIterator, Json}; | ||
use rust_bridge::c::CustomInto; | ||
|
||
pub type JsonC = std::ffi::c_char; | ||
|
||
unsafe impl CustomInto<Json> for *mut JsonC { | ||
unsafe fn custom_into(self) -> Json { | ||
let s = std::ffi::CStr::from_ptr(self).to_str().unwrap(); | ||
serde_json::from_str::<serde_json::Value>(s).unwrap().into() | ||
} | ||
} | ||
|
||
unsafe impl CustomInto<*mut JsonC> for Json { | ||
unsafe fn custom_into(self) -> *mut JsonC { | ||
let s = serde_json::to_string(&self).unwrap(); | ||
std::ffi::CString::new(s).unwrap().into_raw() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,6 @@ pub mod javascript; | |
|
||
#[cfg(feature = "python")] | ||
pub mod python; | ||
|
||
#[cfg(feature = "c")] | ||
pub mod c; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.