Slackbot
11/15/2023, 8:16 AMKishore Nallan
11/15/2023, 8:16 AMcrapthings
11/15/2023, 8:36 AMcrapthings
11/15/2023, 8:45 AMKishore Nallan
11/15/2023, 8:46 AMcrapthings
11/16/2023, 7:51 AMcrapthings
11/16/2023, 7:53 AMKishore Nallan
11/16/2023, 7:56 AMcrapthings
11/16/2023, 7:58 AMKishore Nallan
11/16/2023, 7:58 AMcrapthings
11/16/2023, 7:59 AMcrapthings
11/16/2023, 8:03 AMKishore Nallan
11/16/2023, 8:04 AMcrapthings
11/16/2023, 8:04 AMcrapthings
11/21/2023, 6:29 AMcrapthings
11/21/2023, 6:29 AMcrapthings
11/21/2023, 6:31 AMcrapthings
11/21/2023, 6:32 AMcrapthings
11/21/2023, 6:36 AMconst fs = require('fs');
const _ = require('lodash')
const Typesense = require('typesense')
const { load, cut } = require('@node-rs/jieba');
const { log } = require('console');
load()
const txt = fs.readFileSync('./5.txt', 'utf8')
const databaseName123 = 'okaytest123'
const client = new Typesense.Client({
'nodes': [{
'host': 'localhost',
'port': '8108',
'protocol': 'http'
}],
'apiKey': 'xyz',
'connectionTimeoutSeconds': 300
})
const schema = {
'name': databaseName123,
'fields': [
{ name: 'title', type: 'string', locale: 'zh' },
{ name: 'text', type: 'string' },
{
name: 'embedding',
type: 'float[]',
embed: {
from: [
'title',
],
model_config: {
model_name: 'ts/all-MiniLM-L12-v2'
}
}
}
]
}
;(async function () {
try {
await client.collections(databaseName123).delete()
} catch {
}
try {
await client.collections().create(schema)
} catch (ex) {
console.log(ex)
}
const text = cut(txt).join(' ')
fs.writeFileSync('./cut.txt', text)
try {
await client.collections(databaseName123).documents().import([
{ id: '1', title: txt, text },
])
} catch (ex) {
console.log(ex)
}
const resp = await client.collections(databaseName123).documents().search({
q: `åę`,
// query_by: 'embedding,title',
query_by: 'text',
// query_by: 'title',
pre_segmented_query: true,
// drop_tokens_threshold: 0, typo_tokens_threshold: 0, prefix: false
// sort_by: '_vector_distance:desc'
}).catch(console.log)
// const result = _.map(resp.hits, (item) => {
// console.log(JSON.stringify(item.highlights, null, 2))
// // return {
// // title: item.document.title,
// // tags: item.document.tags,
// // distance: item.vector_distance,
// // }
// })
console.log(JSON.stringify(resp, null, 2))
// console.log(JSON.stringify(resp, null, 2))
// console.log(await client.collections().retrieve())
} ())crapthings
11/21/2023, 6:38 AMKishore Nallan
11/21/2023, 7:44 AMcrapthings
11/21/2023, 7:55 AMcrapthings
11/21/2023, 8:33 AMKishore Nallan
11/22/2023, 5:15 AMit returns random resultThe issue is that for very large documents we have to wrap the word offsets after 64,000 positions. The highlighting is not taking that into consideration. So you are getting correct results, but the wrong word is highlighted in the snippet because of the wrap around.
crapthings
11/22/2023, 6:16 AMKishore Nallan
11/22/2023, 6:17 AMcrapthings
11/22/2023, 6:19 AMKishore Nallan
11/22/2023, 6:20 AMKishore Nallan
11/22/2023, 6:20 AMcrapthings
11/22/2023, 6:30 AMShould we compare and process highly similar texts outside Typesense, or should we use Typesense's built-in similarity feature and implement a deduplication mechanism?crapthings
11/22/2023, 6:32 AMIs there a way to deduplicate after partitioning or chunk?crapthings
11/22/2023, 6:34 AMKishore Nallan
11/22/2023, 8:24 AMparent_doc_id field. Then during searching just do a group_by=parent_doc_id