Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
Curio
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jim Wallace
Curio
Commits
2faafc4c
Commit
2faafc4c
authored
1 year ago
by
Mingchung Xia
Browse files
Options
Downloads
Patches
Plain Diff
Added basic hnsw query test (raw vector result)
parent
b530eb8a
No related branches found
No related tags found
1 merge request
!13
HNSW Implementation with Testcases
Pipeline
#111256
failed
1 year ago
Stage: build
Stage: test
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Tests/SwiftNLPTests/2. Encoding/HNSWTests.swift
+33
-0
33 additions, 0 deletions
Tests/SwiftNLPTests/2. Encoding/HNSWTests.swift
with
33 additions
and
0 deletions
Tests/SwiftNLPTests/2. Encoding/HNSWTests.swift
+
33
−
0
View file @
2faafc4c
...
...
@@ -103,6 +103,39 @@ final class HNSWTests: XCTestCase {
XCTAssert
(
corpus
.
count
==
17999
)
}
// Refer to AllMiniLM_sampleTest.swift for reference
func
testBasicQueryExample
()
async
throws
{
let
docs
=
[
"The quick brown fox jumps over the lazy dog"
,
"I enjoy taking long walks along the beach at sunset"
,
"Advances in neural networks have enabled new AI capabilities"
,
"The stock market experienced a significant downturn last week"
,
"Cooking a good meal can be both an art and a science"
,
"The exploration of space is both challenging and rewarding"
,
"Machine learning models are becoming increasingly sophisticated"
,
"I love reading about history and ancient civilizations"
]
let
query
=
"I like to read about new technology and artificial intelligence"
let
_documentEncoder
=
ContextFreeEncoder
<
Double
>
(
source
:
.
glove6B50d
)
var
corpus
=
HNSWCorpus
(
encoder
:
_documentEncoder
)
corpus
.
addUntokenizedDocuments
(
docs
)
let
size
=
MemoryLayout
.
size
(
ofValue
:
corpus
)
print
(
"Approximate memory footprint:
\(
size
)
bytes"
)
do
{
print
(
"Attempting to query corpus.encodedDocuments.find()..."
)
let
query_embedding
:
[
Double
]
=
_documentEncoder
.
encodeToken
(
query
)
.
map
{
Double
(
$0
)
}
let
results
=
try
corpus
.
encodedDocuments
.
find
(
near
:
query_embedding
,
limit
:
8
)
print
(
results
)
print
(
"Query successful!"
)
}
catch
{
print
(
"Error when trying corpus.encodedDocuments.find:
\(
error
)
"
)
}
}
}
#endif
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment