@@ -198,12 +198,12 @@ def search()
198
198
```
199
199
200
200
201
- #### self.qryr.question
201
+ #### self.qryr.question扩展问题
202
202
203
203
传入查询的问题文本,进行一系列的处理:
204
204
- 输入预处理:` 移除标点、换行符等噪声,全角转半角 ` + ` 去除中英文常见虚词和语气词 `
205
- - 存在非中文词语时处理:
206
- - 只存在中文词语时处理:
205
+ - 存在非中文词语时处理
206
+ - 只存在中文词语时处理
207
207
208
208
##### 输入预处理
209
209
@@ -424,23 +424,6 @@ result = [
424
424
```
425
425
426
426
427
- ------
428
-
429
- ** 意图解析:**
430
-
431
-
432
-
433
-
434
-
435
-
436
-
437
- ------
438
-
439
- ** 语义扩展:**
440
-
441
- ------
442
-
443
-
444
427
##### 只存在中文时
445
428
446
429
@@ -579,7 +562,7 @@ def score_(self, tfts):
579
562
- 然后将 ` tk ` 存放在 ` tms ` 中
580
563
-----
581
564
582
- 最终进行数据的拼接:各种权重的配置拼接查询表达式
565
+ 最终进行数据的拼接:各种权重的配置拼接
583
566
584
567
``` python
585
568
tms = " " .join([f " ( { t} )^ { w} " for t, w in tms])
@@ -604,15 +587,36 @@ if qs:
604
587
), keywords
605
588
```
606
589
607
- #### self.get_vector
608
-
590
+ #### self.get_vector转化原始问题为向量
609
591
610
- #### self.dataStore.search
592
+ 直接使用向量模型转化问题为向量,检查维度 ` shape ` 是否为 1,然后将向量数据转化为 ` float ` 数据数组,动态生成向量列名: ` q_{向量长度}_vec `
611
593
594
+ ``` python
595
+ def get_vector (self , txt , emb_mdl , topk = 10 , similarity = 0.1 ):
596
+ qv, _ = emb_mdl.encode_queries(txt)
597
+ shape = np.array(qv).shape
598
+ if len (shape) > 1 :
599
+ raise Exception (
600
+ f " Dealer.get_vector returned array's shape { shape} doesn't match expectation(exact one dimension). " )
601
+ embedding_data = [get_float(v) for v in qv]
602
+ vector_column_name = f " q_ { len (embedding_data)} _vec "
603
+ return MatchDenseExpr(vector_column_name, embedding_data, ' float' , ' cosine' , topk, {" similarity" : similarity})
604
+ ```
612
605
613
- #### 检索逻辑总结
606
+ #### self.dataStore.search使用原始问题向量和扩展问题后的数据进行检索
614
607
608
+ ` this.dataStore ` 本质就是 ` ES/Infinity ` ,直接调用了对应的 ` search() ` 方法进行检索
615
609
610
+ ``` python
611
+ if lower_case_doc_engine == " elasticsearch" :
612
+ docStoreConn = rag.utils.es_conn.ESConnection()
613
+ elif lower_case_doc_engine == " infinity" :
614
+ docStoreConn = rag.utils.infinity_conn.InfinityConnection()
615
+ else :
616
+ raise Exception (f " Not supported doc engine: { DOC_ENGINE } " )
617
+
618
+ retrievaler = search.Dealer(docStoreConn)
619
+ ```
616
620
617
621
-----
618
622
0 commit comments