Skip to content

Timescale vector autoretrieval

TimescaleVectorAutoretrievalPack #

Bases: BaseLlamaPack

时间尺度向量自动检索包。

Source code in llama_index/packs/timescale_vector_autoretrieval/base.py
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
class TimescaleVectorAutoretrievalPack(BaseLlamaPack):
    """时间尺度向量自动检索包。"""

    def __init__(
        self,
        service_url: str,
        table_name: str,
        time_partition_interval: timedelta,
        vector_store_info: VectorStoreInfo,
        nodes: Optional[List[TextNode]] = None,
        **kwargs: Any,
    ) -> None:
        """初始化参数。"""
        self._vector_store = TimescaleVectorStore.from_params(
            service_url=service_url,
            table_name=table_name,
            time_partition_interval=time_partition_interval,
        )

        if nodes is not None:
            self._storage_context = StorageContext.from_defaults(
                vector_store=self._vector_store
            )
            self._index = VectorStoreIndex(
                nodes, storage_context=self._storage_context, **kwargs
            )
        else:
            self._index = VectorStoreIndex.from_vector_store(
                self._vector_store, **kwargs
            )
            self._storage_context = self._index.storage_context

        self.retriever = VectorIndexAutoRetriever(
            self._index, vector_store_info=vector_store_info
        )
        self.query_engine = RetrieverQueryEngine(self.retriever)

    def get_modules(self) -> Dict[str, Any]:
        """获取模块。"""
        return {
            "vector_store": self._vector_store,
            "storage_context": self._storage_context,
            "index": self._index,
            "retriever": self.retriever,
            "query_engine": self.query_engine,
        }

    def retrieve(self, query_str: str) -> Any:
        """检索。"""
        return self.retriever.retrieve(query_str)

    def run(self, *args: Any, **kwargs: Any) -> Any:
        """运行流水线。"""
        return self.query_engine.query(*args, **kwargs)

get_modules #

get_modules() -> Dict[str, Any]

获取模块。

Source code in llama_index/packs/timescale_vector_autoretrieval/base.py
56
57
58
59
60
61
62
63
64
def get_modules(self) -> Dict[str, Any]:
    """获取模块。"""
    return {
        "vector_store": self._vector_store,
        "storage_context": self._storage_context,
        "index": self._index,
        "retriever": self.retriever,
        "query_engine": self.query_engine,
    }

retrieve #

retrieve(query_str: str) -> Any

检索。

Source code in llama_index/packs/timescale_vector_autoretrieval/base.py
66
67
68
def retrieve(self, query_str: str) -> Any:
    """检索。"""
    return self.retriever.retrieve(query_str)

run #

run(*args: Any, **kwargs: Any) -> Any

运行流水线。

Source code in llama_index/packs/timescale_vector_autoretrieval/base.py
70
71
72
def run(self, *args: Any, **kwargs: Any) -> Any:
    """运行流水线。"""
    return self.query_engine.query(*args, **kwargs)