MCPcopy Index your code
hub / github.com/1Panel-dev/MaxKB / _batch_save

Method _batch_save

apps/knowledge/vector/pg_vector.py:79–110  ·  view source on GitHub ↗
(self, text_list: List[Dict], embedding: Embeddings, is_the_task_interrupted)

Source from the content-addressed store, hash-verified

77 return True
78
79 def _batch_save(self, text_list: List[Dict], embedding: Embeddings, is_the_task_interrupted):
80 texts = [normalize_for_embedding(row.get("text")) for row in text_list]
81 embeddings = embedding.embed_documents(texts)
82 embedding_list = [
83 Embedding(
84 id=uuid.uuid7(),
85 document_id=text_list[index].get("document_id"),
86 paragraph_id=text_list[index].get("paragraph_id"),
87 knowledge_id=text_list[index].get("knowledge_id"),
88 is_active=text_list[index].get("is_active", True),
89 source_id=text_list[index].get("source_id"),
90 source_type=text_list[index].get("source_type"),
91 embedding=[float(x) for x in embeddings[index]],
92 search_vector=SearchVector(
93 Value(
94 to_ts_vector(
95 texts[index],
96 user_words=list(
97 QuerySet(Termbase)
98 .filter(knowledge_id=text_list[index]["knowledge_id"])
99 .values_list("content", flat=True)
100 ),
101 )
102 ),
103 config='simple',
104 ),
105 )
106 for index in range(0, len(texts))
107 ]
108 if not is_the_task_interrupted():
109 QuerySet(Embedding).bulk_create(embedding_list) if len(embedding_list) > 0 else None
110 return True
111
112 def hit_test(
113 self,

Callers

nothing calls this directly

Calls 6

normalize_for_embeddingFunction · 0.90
EmbeddingClass · 0.90
to_ts_vectorFunction · 0.90
is_the_task_interruptedFunction · 0.85
getMethod · 0.45
embed_documentsMethod · 0.45

Tested by

no test coverage detected