token_counter = TokenCountingHandler( tokenizer=tiktoken.encoding_for_model('text-embedding-ada-002').encode, verbose=False # set to true to see usage printed to the console ) token_counter_callback_manager = CallbackManager([token_counter]) embed_model = OpenAIEmbedding(mode='similarity', embed_batch_size=2000, api_key=openai_key, callback_manager=token_counter_callback_manager) splitter = TokenTextSplitter( chunk_size=project_chunk_size, chunk_overlap=20 ) index = VectorStoreIndex.from_vector_store(vector_store=vector_store, embed_model=embed_model) ## Then indexing documents: content_nodes = splitter.get_nodes_from_documents([document]) index.insert_nodes(content_nodes) tokens_used += token_counter.total_embedding_token_count # 0!
index = VectorStoreIndex.from_vector_store(vector_store=vector_store, embed_model=embed_model, callback_manager=callback_manager)
index.as_chat_engine(similarity_top_k=6, node_postprocessors=[FlagEmbeddingRerank(top_n=2)]) # or rerank = FlagEmbeddingRerank(top_n=2) nodes = retriever.retrieve("query") nodes = rerank.postprocess_nodes(nodes)