MCPcopy Create free account
hub / github.com/TaskingAI/TaskingAI / update_record

Function update_record

backend/app/database_ops/retrieval/record/update.py:8–86  ·  view source on GitHub ↗

Update record :param collection: the collection where the record belongs to :param record: the record to be updated :param title: the record title :param type: the record type :param content: the record content :param chunk_text_list: the text list of the chunks to be up

(
    collection: Collection,
    record: Record,
    title: Optional[str],
    type: Optional[RecordType],
    content: Optional[str],
    chunk_text_list: Optional[List[str]],
    chunk_embedding_list: Optional[List[List[float]]],
    chunk_num_tokens_list: Optional[List[int]],
    metadata: Optional[Dict],
)

Source from the content-addressed store, hash-verified

6
7
8async def update_record(
9 collection: Collection,
10 record: Record,
11 title: Optional[str],
12 type: Optional[RecordType],
13 content: Optional[str],
14 chunk_text_list: Optional[List[str]],
15 chunk_embedding_list: Optional[List[List[float]]],
16 chunk_num_tokens_list: Optional[List[int]],
17 metadata: Optional[Dict],
18) -> None:
19 """
20 Update record
21 :param collection: the collection where the record belongs to
22 :param record: the record to be updated
23 :param title: the record title
24 :param type: the record type
25 :param content: the record content
26 :param chunk_text_list: the text list of the chunks to be updated
27 :param chunk_embedding_list: the embedding list of the chunks to be updated
28 :param chunk_num_tokens_list: the num_tokens list of the chunks to be updated
29 :param metadata: the record metadata
30 :return: None
31 """
32 collection_id = collection.collection_id
33
34 # build update dict
35 update_dict = {}
36 if title is not None:
37 update_dict["title"] = title
38 if type is not None:
39 update_dict["type"] = type.value
40 if metadata is not None:
41 update_dict["metadata"] = metadata
42 if content is not None:
43 update_dict["content"] = content
44
45 async with postgres_pool.get_db_connection() as conn:
46 async with conn.transaction():
47 if chunk_text_list is not None and chunk_embedding_list is not None and chunk_num_tokens_list is not None:
48 # 1. delete old chunks
49 old_num_chunks = await delete_record_chunks(
50 conn=conn,
51 collection_id=collection_id,
52 record_id=record.record_id,
53 )
54
55 # 2. insert new chunks
56 await insert_record_chunks(
57 conn=conn,
58 collection_id=collection_id,
59 record_id=record.record_id,
60 chunk_text_list=chunk_text_list,
61 chunk_embedding_list=chunk_embedding_list,
62 chunk_num_tokens_list=chunk_num_tokens_list,
63 )
64
65 # 3. update record num_chunks

Callers

nothing calls this directly

Calls 5

update_objectFunction · 0.90
delete_record_chunksFunction · 0.85
insert_record_chunksFunction · 0.85
get_db_connectionMethod · 0.80
executeMethod · 0.45

Tested by

no test coverage detected