Skip to content

Commit 42251c3

Browse files
committed
Added fingerprint example [skip ci]
1 parent 9f29095 commit 42251c3

3 files changed

Lines changed: 29 additions & 0 deletions

File tree

‎README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Or check out an example:
1818
- [Embeddings](examples/openai/example.R) with OpenAI
1919
- [Binary embeddings](examples/cohere/example.R) with Cohere
2020
- [Sparse search](examples/sparse/example.R) with Text Embeddings Inference
21+
- [Molecular fingerprints](examples/fingerprint/example.R) with ChemmineR
2122

2223
## DBI
2324

‎examples/fingerprint/Description‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Package: example
2+
Version: 0.1.0
3+
Imports:
4+
ChemmineR,
5+
DBI,
6+
RPostgres
7+
Remotes:
8+
bioc::release/ChemmineR

‎examples/fingerprint/example.R‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# good resource
2+
# https://www.bioconductor.org/packages/release/bioc/vignettes/ChemmineR/inst/doc/ChemmineR.html
3+
4+
library(ChemmineR)
5+
library(DBI)
6+
7+
db <- dbConnect(RPostgres::Postgres(), dbname="pgvector_example")
8+
9+
invisible(dbExecute(db, "CREATE EXTENSION IF NOT EXISTS vector"))
10+
invisible(dbExecute(db, "DROP TABLE IF EXISTS molecules"))
11+
invisible(dbExecute(db, "CREATE TABLE molecules (id text PRIMARY KEY, fingerprint bit(1024))"))
12+
13+
data(sdfsample)
14+
fpset <- desc2fp(sdf2ap(sdfsample))
15+
molecules <- data.frame(id=sdfid(sdfsample), fingerprint=as.character(fpset))
16+
invisible(dbAppendTable(db, "molecules", molecules))
17+
18+
params <- list(molecules$fingerprint[[1]])
19+
result <- dbGetQuery(db, "SELECT id FROM molecules ORDER BY fingerprint <%> $1 LIMIT 5", params=params)
20+
print(result$id)

0 commit comments

Comments
 (0)