microsoft/TypeAgent

Public

mirrored from https://github.com/microsoft/TypeAgentAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
15dbaca1b0dc32f141b0d9f0c1b0d37b438f182e

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

python/kp/knowpro/convindex.py

76lines · modecode

1# Copyright (c) Microsoft Corporation.
2# Licensed under the MIT License.
3
4from dataclasses import dataclass, field
5from typing import Callable
6
7from .interfaces import (
8 # Interfaces.
9 IConversation,
10 IMessage,
11 ITermToSemanticRefIndex,
12 ITermToSemanticRefIndexData,
13 # Other imports.
14 IndexingEventHandlers,
15 IndexingResults,
16 Knowledge,
17 KnowledgeType,
18 MessageIndex,
19 ScoredSemanticRef,
20 SemanticRef,
21 TextLocation,
22 TextRange,
23)
24
25
26def text_range_from_location(
27 message_index: MessageIndex,
28 chunk_index: int = 0,
29) -> TextRange:
30 return TextRange(
31 start=TextLocation(message_index, chunk_index),
32 end=None,
33 )
34
35
36type KnowledgeValidator = Callable[
37 [
38 KnowledgeType, # knowledge_type
39 Knowledge, # knowledge
40 ],
41 bool,
42]
43
44
45def add_metadata_to_index[TMessage: IMessage](
46 messages: list[TMessage],
47 semantic_refs: list[SemanticRef],
48 semantic_ref_index: ITermToSemanticRefIndex,
49 knowledge_validator: KnowledgeValidator | None = None,
50) -> None:
51 raise NotImplementedError
52
53
54@dataclass
55class ConversationIndex(ITermToSemanticRefIndex):
56 _map: dict[str, list[ScoredSemanticRef]]
57
58 def __init__(self, data: ITermToSemanticRefIndexData | None = None):
59 self._map = {}
60 if data:
61 self.deserialize(data)
62
63 # TODO: More methods
64
65 def deserialize(self, data: ITermToSemanticRefIndexData) -> None:
66 raise NotImplementedError
67
68
69# ...
70
71
72async def build_conversation_index(
73 conversation: IConversation,
74 event_handler: IndexingEventHandlers | None = None,
75) -> IndexingResults:
76 raise NotImplementedError
77