(
self,
create_dict: Dict,
**kwargs,
)
| 64 | |
| 65 | class RecordModelOperator(PostgresModelOperator): |
| 66 | async def create( |
| 67 | self, |
| 68 | create_dict: Dict, |
| 69 | **kwargs, |
| 70 | ) -> ModelEntity: |
| 71 | # handle kwargs |
| 72 | self._check_kwargs(object_id_required=None, **kwargs) |
| 73 | collection_id = kwargs["collection_id"] |
| 74 | |
| 75 | type = RecordType(create_dict["type"]) |
| 76 | title = create_dict["title"] |
| 77 | content = create_dict["content"] |
| 78 | text_splitter = TextSplitter(**create_dict["text_splitter"]) |
| 79 | metadata = create_dict["metadata"] |
| 80 | |
| 81 | # validate collection |
| 82 | collection = await collection_ops.get(collection_id=collection_id) |
| 83 | |
| 84 | # split content into chunks |
| 85 | chunk_text_list, num_tokens_list, embeddings, db_content = await process_content( |
| 86 | collection=collection, |
| 87 | type=type, |
| 88 | title=title, |
| 89 | content=create_dict.get("content"), |
| 90 | file_id=create_dict.get("file_id"), |
| 91 | url=create_dict.get("url"), |
| 92 | text_splitter=text_splitter, |
| 93 | max_num_chunks=collection.rest_capacity(), |
| 94 | ) |
| 95 | |
| 96 | # create record |
| 97 | new_record_id = Record.generate_random_id() |
| 98 | await db_record.create_record_and_chunks( |
| 99 | record_id=new_record_id, |
| 100 | collection=collection, |
| 101 | chunk_text_list=chunk_text_list, |
| 102 | chunk_embedding_list=embeddings, |
| 103 | chunk_num_tokens_list=num_tokens_list, |
| 104 | title=title, |
| 105 | type=type, |
| 106 | content=db_content, |
| 107 | metadata=metadata, |
| 108 | ) |
| 109 | |
| 110 | # get the created record |
| 111 | record = await self.get(collection_id=collection_id, record_id=new_record_id) |
| 112 | |
| 113 | return record |
| 114 | |
| 115 | async def update( |
| 116 | self, |
nothing calls this directly
no test coverage detected