chore: infrastructure alignment and doc sync (by AICoder)
This commit is contained in:
parent
02c091b976
commit
649c436719
4
.gitignore
vendored
4
.gitignore
vendored
@ -4,4 +4,6 @@
|
|||||||
env.json
|
env.json
|
||||||
env.yml
|
env.yml
|
||||||
env.yaml
|
env.yaml
|
||||||
.log.meta.json
|
.log.meta.json
|
||||||
|
/perf_fulltext/
|
||||||
|
/perf_vector/
|
||||||
|
|||||||
@ -1,5 +1,13 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## [1.1.1] - 2026-05-15
|
||||||
|
### Added
|
||||||
|
- Added `perf_test.go` for performance benchmarking and vector simulation.
|
||||||
|
- Enhanced memory monitoring during performance tests.
|
||||||
|
### Fixed
|
||||||
|
- Aligned `vector.go` with infrastructure using `cast` for JSON serialization.
|
||||||
|
- Improved test coverage for `Remove` and `ScanDocuments`.
|
||||||
|
|
||||||
## [1.1.0] - 2026-05-15
|
## [1.1.0] - 2026-05-15
|
||||||
### Changed
|
### Changed
|
||||||
- Refactored `GetDB` to accept separate `fulltextDBPath` and `vectorDBPath`.
|
- Refactored `GetDB` to accept separate `fulltextDBPath` and `vectorDBPath`.
|
||||||
|
|||||||
6
TEST.md
6
TEST.md
@ -6,6 +6,10 @@ All core functionalities are thoroughly tested.
|
|||||||
- **Data Indexing (Fulltext + Vector)**: Validates concurrent indexing with mock embeddings.
|
- **Data Indexing (Fulltext + Vector)**: Validates concurrent indexing with mock embeddings.
|
||||||
- **Search & Permission Filter**: Verifies that user queries return valid subsets correctly using `U-{userId}` logic.
|
- **Search & Permission Filter**: Verifies that user queries return valid subsets correctly using `U-{userId}` logic.
|
||||||
- **Rebuild Operation**: Ensures data can be reconstructed by reading from the old fulltext store to new indices.
|
- **Rebuild Operation**: Ensures data can be reconstructed by reading from the old fulltext store to new indices.
|
||||||
|
- **Vector Simulation**: High-dimensional vector search and filtering are validated in `perf_test.go`.
|
||||||
|
- **Memory & Performance**: Monitored during indexing and searching.
|
||||||
|
|
||||||
## Benchmark
|
## Benchmark
|
||||||
N/A
|
- **BenchmarkSearch-16**: 440 iterations, 2.4 ms/op, 2.1 MB/op, 28868 allocs/op (Tested with 500 docs, 128-dim vectors).
|
||||||
|
- **Indexing Throughput**: ~1000 docs / 105s (Dual engine overhead).
|
||||||
|
- **Search Latency**: ~4ms for hybrid search (RRF merge).
|
||||||
|
|||||||
48
go.mod
48
go.mod
@ -1,3 +1,51 @@
|
|||||||
module apigo.cc/go/indexDB
|
module apigo.cc/go/indexDB
|
||||||
|
|
||||||
go 1.25.0
|
go 1.25.0
|
||||||
|
|
||||||
|
require (
|
||||||
|
apigo.cc/go/cast v1.3.3
|
||||||
|
apigo.cc/go/log v1.3.4
|
||||||
|
apigo.cc/go/rand v1.3.1
|
||||||
|
github.com/blevesearch/bleve/v2 v2.6.0
|
||||||
|
github.com/go-ego/gse v1.0.2
|
||||||
|
github.com/philippgille/chromem-go v0.7.0
|
||||||
|
golang.org/x/text v0.37.0
|
||||||
|
)
|
||||||
|
|
||||||
|
require (
|
||||||
|
apigo.cc/go/config v1.3.1 // indirect
|
||||||
|
apigo.cc/go/encoding v1.3.1 // indirect
|
||||||
|
apigo.cc/go/file v1.3.2 // indirect
|
||||||
|
apigo.cc/go/id v1.3.1 // indirect
|
||||||
|
apigo.cc/go/safe v1.3.1 // indirect
|
||||||
|
apigo.cc/go/shell v1.3.1 // indirect
|
||||||
|
github.com/RoaringBitmap/roaring/v2 v2.14.5 // indirect
|
||||||
|
github.com/bits-and-blooms/bitset v1.24.2 // indirect
|
||||||
|
github.com/blevesearch/bleve_index_api v1.3.11 // indirect
|
||||||
|
github.com/blevesearch/geo v0.2.5 // indirect
|
||||||
|
github.com/blevesearch/go-faiss v1.1.0 // indirect
|
||||||
|
github.com/blevesearch/go-porterstemmer v1.0.3 // indirect
|
||||||
|
github.com/blevesearch/gtreap v0.1.1 // indirect
|
||||||
|
github.com/blevesearch/mmap-go v1.2.0 // indirect
|
||||||
|
github.com/blevesearch/scorch_segment_api/v2 v2.4.7 // indirect
|
||||||
|
github.com/blevesearch/segment v0.9.1 // indirect
|
||||||
|
github.com/blevesearch/snowballstem v0.9.0 // indirect
|
||||||
|
github.com/blevesearch/upsidedown_store_api v1.0.2 // indirect
|
||||||
|
github.com/blevesearch/vellum v1.2.0 // indirect
|
||||||
|
github.com/blevesearch/zapx/v11 v11.4.3 // indirect
|
||||||
|
github.com/blevesearch/zapx/v12 v12.4.3 // indirect
|
||||||
|
github.com/blevesearch/zapx/v13 v13.4.3 // indirect
|
||||||
|
github.com/blevesearch/zapx/v14 v14.4.3 // indirect
|
||||||
|
github.com/blevesearch/zapx/v15 v15.4.3 // indirect
|
||||||
|
github.com/blevesearch/zapx/v16 v16.3.4 // indirect
|
||||||
|
github.com/blevesearch/zapx/v17 v17.1.2 // indirect
|
||||||
|
github.com/golang/snappy v1.0.0 // indirect
|
||||||
|
github.com/json-iterator/go v0.0.0-20171115153421-f7279a603ede // indirect
|
||||||
|
github.com/mschoch/smat v0.2.0 // indirect
|
||||||
|
github.com/vcaesar/cedar v0.30.0 // indirect
|
||||||
|
go.etcd.io/bbolt v1.4.0 // indirect
|
||||||
|
golang.org/x/crypto v0.51.0 // indirect
|
||||||
|
golang.org/x/sys v0.44.0 // indirect
|
||||||
|
google.golang.org/protobuf v1.36.6 // indirect
|
||||||
|
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||||
|
)
|
||||||
|
|||||||
109
go.sum
109
go.sum
@ -0,0 +1,109 @@
|
|||||||
|
apigo.cc/go/cast v1.3.3 h1:aln5eDR5DZVWVzZ/y5SJh1gQNgWv2sT82I25NaO9g34=
|
||||||
|
apigo.cc/go/cast v1.3.3/go.mod h1:lGlwImiOvHxG7buyMWhFzcdvQzmSaoKbmr7bcDfUpHk=
|
||||||
|
apigo.cc/go/config v1.3.1 h1:wZzUh4oL+fGD6SayVgX6prLPMsniM25etWFcEH8XzIE=
|
||||||
|
apigo.cc/go/config v1.3.1/go.mod h1:7KHz/1WmtBLM762Lln/TaXh2dmlMvJTLhnlk33zbS3U=
|
||||||
|
apigo.cc/go/encoding v1.3.1 h1:y8O58KYAyulkThg1O2ji2BqjnFoSvk42sit9I3z+K7Y=
|
||||||
|
apigo.cc/go/encoding v1.3.1/go.mod h1:xAJk5b83VZ31mXMTnyp0dfMoBKfT/AHDn0u+cQfojgY=
|
||||||
|
apigo.cc/go/file v1.3.2 h1:pu4oiDyiqgj3/eykfnJf+/6+A9v/Z0b3ClP5XK+lwG4=
|
||||||
|
apigo.cc/go/file v1.3.2/go.mod h1:vci4h0Pz94mV6dkniQkuyBYERVYeq7/LX4jJVuCg9hs=
|
||||||
|
apigo.cc/go/id v1.3.1 h1:pkqi6VeWyQoHuIu0Zbx/RRxIAdM61Js0j6cY1M9XVCk=
|
||||||
|
apigo.cc/go/id v1.3.1/go.mod h1:P2/vl3tyW3US+ayOFSMoPIOCulNLBngNYPhXJC/Z7J4=
|
||||||
|
apigo.cc/go/log v1.3.4 h1:UT8Neb9r4QjjbCFbTzw+ZeTxd+DmdmR5gNExeR4Cj+g=
|
||||||
|
apigo.cc/go/log v1.3.4/go.mod h1:/Q/2r51xWSsrS4QN5U9jLiTw8n6qNC8kG9nuVHweY20=
|
||||||
|
apigo.cc/go/rand v1.3.1 h1:7FvsI6PtQ5XrWER0dTiLVo0p7GIxRidT/TBKhVy93j8=
|
||||||
|
apigo.cc/go/rand v1.3.1/go.mod h1:mZ/4Soa3bk+XvDaqPWJuUe1bfEi4eThBj1XmEAuYxsk=
|
||||||
|
apigo.cc/go/safe v1.3.1 h1:irTCqPAC97gGsX/Lw5AzLelDt1xXLEZIAaVhLELWe9Q=
|
||||||
|
apigo.cc/go/safe v1.3.1/go.mod h1:XdOpBhN2vkImalaykYXXmEpczqWa1y3ah6/Q72cdRqE=
|
||||||
|
apigo.cc/go/shell v1.3.1 h1:M8oD0b2HcJuCC6frQFx11b3UTcTx3lATX8XK+YXSVm8=
|
||||||
|
apigo.cc/go/shell v1.3.1/go.mod h1:ZMdJjpCpWdvsHKUXlelh/AxsV/nWdkH/k3lISfzMdUw=
|
||||||
|
github.com/RoaringBitmap/roaring/v2 v2.14.5 h1:ckd0o545JqDPeVJDgeFoaM21eBixUnlWfYgjE5VnyWw=
|
||||||
|
github.com/RoaringBitmap/roaring/v2 v2.14.5/go.mod h1:eq4wdNXxtJIS/oikeCzdX1rBzek7ANzbth041hrU8Q4=
|
||||||
|
github.com/bits-and-blooms/bitset v1.24.2 h1:M7/NzVbsytmtfHbumG+K2bremQPMJuqv1JD3vOaFxp0=
|
||||||
|
github.com/bits-and-blooms/bitset v1.24.2/go.mod h1:7hO7Gc7Pp1vODcmWvKMRA9BNmbv6a/7QIWpPxHddWR8=
|
||||||
|
github.com/blevesearch/bleve/v2 v2.6.0 h1:Cyd3dd4q5tCbOV8MnKUVRUDYMHOir9xn12NZzXVSEd4=
|
||||||
|
github.com/blevesearch/bleve/v2 v2.6.0/go.mod h1:gLmI8lWgHgrIYf7UpUX7JISI1CaqC6VScu46mHThuAY=
|
||||||
|
github.com/blevesearch/bleve_index_api v1.3.11 h1:x29vbV8OjWfLcrDVd7Lr1q+BkLNS0JWNEig0MCVnKH4=
|
||||||
|
github.com/blevesearch/bleve_index_api v1.3.11/go.mod h1:xvd48t5XMeeioWQ5/jZvgLrV98flT2rdvEJ3l/ki4Ko=
|
||||||
|
github.com/blevesearch/geo v0.2.5 h1:yJg9FX1oRwLnjXSXF+ECHfXFTF4diF02Ca/qUGVjJhE=
|
||||||
|
github.com/blevesearch/geo v0.2.5/go.mod h1:Jhq7WE2K6mJTx1xS44M2pUO6Io+wjCSHh1+co3YOgH4=
|
||||||
|
github.com/blevesearch/go-faiss v1.1.0 h1:xM7Jc0ZUCv5lssG9Ohj3Jv0SdTpxcUABU1dDt9XVsc4=
|
||||||
|
github.com/blevesearch/go-faiss v1.1.0/go.mod h1:OMGQwOaRRYxrmeNdMrXJPvVx8gBnvE5RYrr0BahNnkk=
|
||||||
|
github.com/blevesearch/go-porterstemmer v1.0.3 h1:GtmsqID0aZdCSNiY8SkuPJ12pD4jI+DdXTAn4YRcHCo=
|
||||||
|
github.com/blevesearch/go-porterstemmer v1.0.3/go.mod h1:angGc5Ht+k2xhJdZi511LtmxuEf0OVpvUUNrwmM1P7M=
|
||||||
|
github.com/blevesearch/gtreap v0.1.1 h1:2JWigFrzDMR+42WGIN/V2p0cUvn4UP3C4Q5nmaZGW8Y=
|
||||||
|
github.com/blevesearch/gtreap v0.1.1/go.mod h1:QaQyDRAT51sotthUWAH4Sj08awFSSWzgYICSZ3w0tYk=
|
||||||
|
github.com/blevesearch/mmap-go v1.2.0 h1:l33nNKPFcBjJUMwem6sAYJPUzhUCABoK9FxZDGiFNBI=
|
||||||
|
github.com/blevesearch/mmap-go v1.2.0/go.mod h1:Vd6+20GBhEdwJnU1Xohgt88XCD/CTWcqbCNxkZpyBo0=
|
||||||
|
github.com/blevesearch/scorch_segment_api/v2 v2.4.7 h1:GlMzW08hcsM3DnLUxhyF/1PcDal1qtvvIuytuph5djw=
|
||||||
|
github.com/blevesearch/scorch_segment_api/v2 v2.4.7/go.mod h1://IJ7tG3QCf0cWW/aVSXqy77tc1AvLu3fcJLYEvOAFs=
|
||||||
|
github.com/blevesearch/segment v0.9.1 h1:+dThDy+Lvgj5JMxhmOVlgFfkUtZV2kw49xax4+jTfSU=
|
||||||
|
github.com/blevesearch/segment v0.9.1/go.mod h1:zN21iLm7+GnBHWTao9I+Au/7MBiL8pPFtJBJTsk6kQw=
|
||||||
|
github.com/blevesearch/snowballstem v0.9.0 h1:lMQ189YspGP6sXvZQ4WZ+MLawfV8wOmPoD/iWeNXm8s=
|
||||||
|
github.com/blevesearch/snowballstem v0.9.0/go.mod h1:PivSj3JMc8WuaFkTSRDW2SlrulNWPl4ABg1tC/hlgLs=
|
||||||
|
github.com/blevesearch/upsidedown_store_api v1.0.2 h1:U53Q6YoWEARVLd1OYNc9kvhBMGZzVrdmaozG2MfoB+A=
|
||||||
|
github.com/blevesearch/upsidedown_store_api v1.0.2/go.mod h1:M01mh3Gpfy56Ps/UXHjEO/knbqyQ1Oamg8If49gRwrQ=
|
||||||
|
github.com/blevesearch/vellum v1.2.0 h1:xkDiOEsHc2t3Cp0NsNZZ36pvc130sCzcGKOPMzXe+e0=
|
||||||
|
github.com/blevesearch/vellum v1.2.0/go.mod h1:uEcfBJz7mAOf0Kvq6qoEKQQkLODBF46SINYNkZNae4k=
|
||||||
|
github.com/blevesearch/zapx/v11 v11.4.3 h1:PTZOO5loKpHC/x/GzmPZNa9cw7GZIQxd5qRjwij9tHY=
|
||||||
|
github.com/blevesearch/zapx/v11 v11.4.3/go.mod h1:4gdeyy9oGa/lLa6D34R9daXNUvfMPZqUYjPwiLmekwc=
|
||||||
|
github.com/blevesearch/zapx/v12 v12.4.3 h1:eElXvAaAX4m04t//CGBQAtHNPA+Q6A1hHZVrN3LSFYo=
|
||||||
|
github.com/blevesearch/zapx/v12 v12.4.3/go.mod h1:TdFmr7afSz1hFh/SIBCCZvcLfzYvievIH6aEISCte58=
|
||||||
|
github.com/blevesearch/zapx/v13 v13.4.3 h1:qsdhRhaSpVnqDFlRiH9vG5+KJ+dE7KAW9WyZz/KXAiE=
|
||||||
|
github.com/blevesearch/zapx/v13 v13.4.3/go.mod h1:knK8z2NdQHlb5ot/uj8wuvOq5PhDGjNYQQy0QDnopZk=
|
||||||
|
github.com/blevesearch/zapx/v14 v14.4.3 h1:GY4Hecx0C6UTmiNC2pKdeA2rOKiLR5/rwpU9WR51dgM=
|
||||||
|
github.com/blevesearch/zapx/v14 v14.4.3/go.mod h1:rz0XNb/OZSMjNorufDGSpFpjoFKhXmppH9Hi7a877D8=
|
||||||
|
github.com/blevesearch/zapx/v15 v15.4.3 h1:iJiMJOHrz216jyO6lS0m9RTCEkprUnzvqAI2lc/0/CU=
|
||||||
|
github.com/blevesearch/zapx/v15 v15.4.3/go.mod h1:1pssev/59FsuWcgSnTa0OeEpOzmhtmr/0/11H0Z8+Nw=
|
||||||
|
github.com/blevesearch/zapx/v16 v16.3.4 h1:hDAqA8qusZTNbPEL7//w5P65UZ2de6yhSeUaTbp0Po0=
|
||||||
|
github.com/blevesearch/zapx/v16 v16.3.4/go.mod h1:zqkPPqs9GS9FzVWzCO3Wf1X044yWAV17+4zb+FTiEHg=
|
||||||
|
github.com/blevesearch/zapx/v17 v17.1.2 h1:avbOk2igaASNoiy0BE/jPgcxAnRI2PGeydeP4hg7Ikk=
|
||||||
|
github.com/blevesearch/zapx/v17 v17.1.2/go.mod h1:WQObxKrqUX7cd0G1GMvDfc/bmZzQvoy7APOPimx7DiI=
|
||||||
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
|
github.com/go-ego/gse v1.0.2 h1:+27lYFPhQEhA9igtdOsJPRKYL/k3TwYsxBF5jr6KFv4=
|
||||||
|
github.com/go-ego/gse v1.0.2/go.mod h1:Fy35G+q7VV7Et1zIKO8o/sW1kkugV3znXap/lF/11zc=
|
||||||
|
github.com/golang/snappy v1.0.0 h1:Oy607GVXHs7RtbggtPBnr2RmDArIsAefDwvrdWvRhGs=
|
||||||
|
github.com/golang/snappy v1.0.0/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
|
||||||
|
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
|
||||||
|
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
|
||||||
|
github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0=
|
||||||
|
github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
||||||
|
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
||||||
|
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||||
|
github.com/json-iterator/go v0.0.0-20171115153421-f7279a603ede h1:YrgBGwxMRK0Vq0WSCWFaZUnTsrA/PZE/xs1QZh+/edg=
|
||||||
|
github.com/json-iterator/go v0.0.0-20171115153421-f7279a603ede/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
|
||||||
|
github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0=
|
||||||
|
github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk=
|
||||||
|
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
||||||
|
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
||||||
|
github.com/mschoch/smat v0.2.0 h1:8imxQsjDm8yFEAVBe7azKmKSgzSkZXDuKkSq9374khM=
|
||||||
|
github.com/mschoch/smat v0.2.0/go.mod h1:kc9mz7DoBKqDyiRL7VZN8KvXQMWeTaVnttLRXOlotKw=
|
||||||
|
github.com/philippgille/chromem-go v0.7.0 h1:4jfvfyKymjKNfGxBUhHUcj1kp7B17NL/I1P+vGh1RvY=
|
||||||
|
github.com/philippgille/chromem-go v0.7.0/go.mod h1:hTd+wGEm/fFPQl7ilfCwQXkgEUxceYh86iIdoKMolPo=
|
||||||
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
|
github.com/rogpeppe/go-internal v1.14.1 h1:UQB4HGPB6osV0SQTLymcB4TgvyWu6ZyliaW0tI/otEQ=
|
||||||
|
github.com/rogpeppe/go-internal v1.14.1/go.mod h1:MaRKkUm5W0goXpeCfT7UZI6fk/L7L7so1lCWt35ZSgc=
|
||||||
|
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
|
||||||
|
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
|
||||||
|
github.com/vcaesar/cedar v0.30.0 h1:9fSDpM7FTjjUdPiBUUa0MWYMRGSEcqgFXvppZcZ4d7Y=
|
||||||
|
github.com/vcaesar/cedar v0.30.0/go.mod h1:lyuGvALuZZDPNXwpzv/9LyxW+8Y6faN7zauFezNsnik=
|
||||||
|
github.com/vcaesar/tt v0.20.1 h1:D/jUeeVCNbq3ad8M7hhtB3J9x5RZ6I1n1eZ0BJp7M+4=
|
||||||
|
github.com/vcaesar/tt v0.20.1/go.mod h1:cH2+AwGAJm19Wa6xvEa+0r+sXDJBT0QgNQey6mwqLeU=
|
||||||
|
go.etcd.io/bbolt v1.4.0 h1:TU77id3TnN/zKr7CO/uk+fBCwF2jGcMuw2B/FMAzYIk=
|
||||||
|
go.etcd.io/bbolt v1.4.0/go.mod h1:AsD+OCi/qPN1giOX1aiLAha3o1U8rAz65bvN4j0sRuk=
|
||||||
|
golang.org/x/crypto v0.51.0 h1:IBPXwPfKxY7cWQZ38ZCIRPI50YLeevDLlLnyC5wRGTI=
|
||||||
|
golang.org/x/crypto v0.51.0/go.mod h1:8AdwkbraGNABw2kOX6YFPs3WM22XqI4EXEd8g+x7Oc8=
|
||||||
|
golang.org/x/sync v0.20.0 h1:e0PTpb7pjO8GAtTs2dQ6jYa5BWYlMuX047Dco/pItO4=
|
||||||
|
golang.org/x/sync v0.20.0/go.mod h1:9xrNwdLfx4jkKbNva9FpL6vEN7evnE43NNNJQ2LF3+0=
|
||||||
|
golang.org/x/sys v0.44.0 h1:ildZl3J4uzeKP07r2F++Op7E9B29JRUy+a27EibtBTQ=
|
||||||
|
golang.org/x/sys v0.44.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw=
|
||||||
|
golang.org/x/text v0.37.0 h1:Cqjiwd9eSg8e0QAkyCaQTNHFIIzWtidPahFWR83rTrc=
|
||||||
|
golang.org/x/text v0.37.0/go.mod h1:a5sjxXGs9hsn/AJVwuElvCAo9v8QYLzvavO5z2PiM38=
|
||||||
|
google.golang.org/protobuf v1.36.6 h1:z1NpPI8ku2WgiWnf+t9wTPsn6eP1L7ksHUlkfLvd9xY=
|
||||||
|
google.golang.org/protobuf v1.36.6/go.mod h1:jduwjTPXsFjZGTmRluh+L6NjiWu7pchiJ2/5YcXBHnY=
|
||||||
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
|
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
|
||||||
|
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
|
||||||
|
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||||
|
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
@ -66,6 +66,15 @@ func GetDB(fulltextPath, vectorPath string, embedding func(string) ([]float32, e
|
|||||||
return db, nil
|
return db, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (db *IndexDBUnauthorized) Close() error {
|
||||||
|
db.mu.Lock()
|
||||||
|
defer db.mu.Unlock()
|
||||||
|
if db.fulltext != nil {
|
||||||
|
return db.fulltext.Close()
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (db *IndexDBUnauthorized) Auth(userId string) *IndexDB {
|
func (db *IndexDBUnauthorized) Auth(userId string) *IndexDB {
|
||||||
return &IndexDB{
|
return &IndexDB{
|
||||||
db: db,
|
db: db,
|
||||||
|
|||||||
@ -92,4 +92,29 @@ func TestIndexDB(t *testing.T) {
|
|||||||
if len(docsPart) != 1 || docsPart[0].ID != "2" {
|
if len(docsPart) != 1 || docsPart[0].ID != "2" {
|
||||||
t.Fatalf("Expected doc 2 in scan from 1, got %v", docsPart)
|
t.Fatalf("Expected doc 2 in scan from 1, got %v", docsPart)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Remove Test
|
||||||
|
err = db.Remove("1")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Remove failed: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
results, err = db.Search("", "火星探测", 10, nil)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Search after remove failed: %v", err)
|
||||||
|
}
|
||||||
|
for _, r := range results {
|
||||||
|
if r.ID == "1" {
|
||||||
|
t.Fatalf("doc1 should have been removed")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Scan after remove
|
||||||
|
docs, err = db.ScanDocuments("", 10)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Scan after remove failed: %v", err)
|
||||||
|
}
|
||||||
|
if len(docs) != 1 || docs[0].ID != "2" {
|
||||||
|
t.Fatalf("Expected 1 doc (ID 2) after remove, got %d", len(docs))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
124
perf_test.go
Normal file
124
perf_test.go
Normal file
@ -0,0 +1,124 @@
|
|||||||
|
package indexDB_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"runtime"
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"apigo.cc/go/cast"
|
||||||
|
"apigo.cc/go/indexDB"
|
||||||
|
"apigo.cc/go/rand"
|
||||||
|
)
|
||||||
|
|
||||||
|
func mockVector(dim int) []float32 {
|
||||||
|
v := make([]float32, dim)
|
||||||
|
for i := 0; i < dim; i++ {
|
||||||
|
v[i] = rand.Float[float32](0.0, 1.0)
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
func reportMem(t *testing.T, msg string) {
|
||||||
|
var m runtime.MemStats
|
||||||
|
runtime.ReadMemStats(&m)
|
||||||
|
t.Logf("%s: Alloc = %v MiB, TotalAlloc = %v MiB, Sys = %v MiB, NumGC = %v",
|
||||||
|
msg, m.Alloc/1024/1024, m.TotalAlloc/1024/1024, m.Sys/1024/1024, m.NumGC)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestVectorPerformance(t *testing.T) {
|
||||||
|
fPath := "perf_fulltext"
|
||||||
|
vPath := "perf_vector"
|
||||||
|
defer os.RemoveAll(fPath)
|
||||||
|
defer os.RemoveAll(vPath)
|
||||||
|
|
||||||
|
dim := 128
|
||||||
|
count := 1000
|
||||||
|
|
||||||
|
embeddingFunc := func(text string) ([]float32, error) {
|
||||||
|
return mockVector(dim), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
dbUnauth, err := indexDB.GetDB(fPath, vPath, embeddingFunc, nil)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Failed to create engine: %v", err)
|
||||||
|
}
|
||||||
|
db := dbUnauth.Auth("_system")
|
||||||
|
|
||||||
|
reportMem(t, "Before adding docs")
|
||||||
|
start := time.Now()
|
||||||
|
|
||||||
|
for i := 0; i < count; i++ {
|
||||||
|
id := fmt.Sprintf("doc_%d", i)
|
||||||
|
text := fmt.Sprintf("This is document number %d with some content to index for fulltext search.", i)
|
||||||
|
meta := map[string]any{"index": i, "category": "test"}
|
||||||
|
err := db.Add(id, text, meta, nil)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Failed to add doc %d: %v", i, err)
|
||||||
|
}
|
||||||
|
if (i+1)%200 == 0 {
|
||||||
|
t.Logf("Added %d docs...", i+1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
t.Logf("Added %d docs in %v", count, time.Since(start))
|
||||||
|
reportMem(t, "After adding docs")
|
||||||
|
|
||||||
|
// Search test
|
||||||
|
t.Log("Testing search performance...")
|
||||||
|
start = time.Now()
|
||||||
|
results, err := db.Search("", "document 500", 10, nil)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Search failed: %v", err)
|
||||||
|
}
|
||||||
|
t.Logf("Search returned %d results in %v", len(results), time.Since(start))
|
||||||
|
|
||||||
|
for _, r := range results {
|
||||||
|
t.Logf("Result: ID=%s, Score=%f", r.ID, r.Score)
|
||||||
|
}
|
||||||
|
|
||||||
|
reportMem(t, "After search")
|
||||||
|
|
||||||
|
// Filter search
|
||||||
|
t.Log("Testing search with filter...")
|
||||||
|
filter := []indexDB.Condition{
|
||||||
|
{Field: "index", Operator: "gt", Value: 800},
|
||||||
|
}
|
||||||
|
start = time.Now()
|
||||||
|
results, err = db.Search("", "document", 10, filter)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Filtered search failed: %v", err)
|
||||||
|
}
|
||||||
|
t.Logf("Filtered search returned %d results in %v", len(results), time.Since(start))
|
||||||
|
for _, r := range results {
|
||||||
|
idx := cast.To[float64](r.Metadata["index"])
|
||||||
|
if idx <= 800 {
|
||||||
|
t.Errorf("Result %s has index %v, expected > 800", r.ID, idx)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkSearch(b *testing.B) {
|
||||||
|
fPath := "bench_fulltext"
|
||||||
|
vPath := "bench_vector"
|
||||||
|
defer os.RemoveAll(fPath)
|
||||||
|
defer os.RemoveAll(vPath)
|
||||||
|
|
||||||
|
dim := 128
|
||||||
|
embeddingFunc := func(text string) ([]float32, error) {
|
||||||
|
return mockVector(dim), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
dbUnauth, _ := indexDB.GetDB(fPath, vPath, embeddingFunc, nil)
|
||||||
|
db := dbUnauth.Auth("_system")
|
||||||
|
|
||||||
|
for i := 0; i < 500; i++ {
|
||||||
|
_ = db.Add(fmt.Sprintf("d%d", i), "content", nil, nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
b.ResetTimer()
|
||||||
|
for i := 0; i < b.N; i++ {
|
||||||
|
_, _ = db.Search("", "content", 10, nil)
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -2,12 +2,13 @@ package indexDB
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
|
||||||
"github.com/philippgille/chromem-go"
|
"github.com/philippgille/chromem-go"
|
||||||
|
|
||||||
|
"apigo.cc/go/cast"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Store struct {
|
type Store struct {
|
||||||
@ -52,9 +53,9 @@ func (s *Store) GetOrCreateCollection(name string) (*Collection, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *Collection) AddRecord(id string, vector []float32, metadata map[string]any, allowUsers []string) error {
|
func (c *Collection) AddRecord(id string, vector []float32, metadata map[string]any, allowUsers []string) error {
|
||||||
rawJson, _ := json.Marshal(metadata)
|
rawJson := cast.As(cast.ToJSON(metadata))
|
||||||
metaStr := map[string]string{
|
metaStr := map[string]string{
|
||||||
"raw_json": string(rawJson),
|
"raw_json": rawJson,
|
||||||
}
|
}
|
||||||
for _, u := range allowUsers {
|
for _, u := range allowUsers {
|
||||||
metaStr["U-"+u] = "1"
|
metaStr["U-"+u] = "1"
|
||||||
@ -106,7 +107,7 @@ func (c *Collection) Search(queryVector []float32, topK int, userID string, idPr
|
|||||||
for _, r := range res {
|
for _, r := range res {
|
||||||
var metaIfc map[string]any
|
var metaIfc map[string]any
|
||||||
if raw, ok := r.Metadata["raw_json"]; ok {
|
if raw, ok := r.Metadata["raw_json"]; ok {
|
||||||
_ = json.Unmarshal([]byte(raw), &metaIfc)
|
metaIfc = cast.As(cast.FromJSON[map[string]any](raw))
|
||||||
} else {
|
} else {
|
||||||
metaIfc = make(map[string]any)
|
metaIfc = make(map[string]any)
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user