Exemple #1
0
    def open(self, rebuild_index):
        self.db = plyvel.DB(self.path, create_if_missing=True)

        self.graph = cwg.new_graph()

        index_path = os.path.splitext(self.path)[0] + ".index"
        print("MemoryGraph: index path", index_path)
        self.index = hnswlib.Index(space=self.space, dim=self.dim) 

        if os.path.isfile(index_path) and not rebuild_index:
            print("MemoryGraph: loading index")
            self.index.load_index(index_path)
            self.index.set_ef(self.ef)
            self.load_all_node_ids()
        else:
            print("MemoryGraph: building index")
            self.index.init_index(max_elements=self.max_elements, ef_construction=self.ef * 2, M=self.M)
            self.index.set_ef(self.ef)
            self.load_all_nodes()
            if cwg.len(self.graph) > 0:
                self.save()
        
        self.load_all_edges()

        print("MemoryGraph:", self.index.get_current_count(), "nodes")
Exemple #2
0
 def index_count(self):
     return cwg.len(self.graph)