SergeyO7 commited on
Commit
63219e4
·
verified ·
1 Parent(s): 369246e

Create app1.py

Browse files
Files changed (1) hide show
  1. app1.py +71 -0
app1.py ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import asyncio
2
+ from llama_index.core import Document
3
+ from llama_index.embeddings.huggingface import HuggingFaceEmbedding
4
+ from llama_index.core.node_parser import SentenceSplitter
5
+ from llama_index.core.ingestion import IngestionPipeline
6
+ from llama_index.core import SimpleDirectoryReader
7
+
8
+ reader = SimpleDirectoryReader(input_dir=r"C:\Users\so7\AppData\Local\Programs\Python\Python313\RAG")
9
+ documents = reader.load_data()
10
+
11
+ # create the pipeline with transformations
12
+ pipeline = IngestionPipeline(
13
+ transformations=[
14
+ SentenceSplitter(chunk_overlap=0),
15
+ HuggingFaceEmbedding(model_name="BAAI/bge-small-en-v1.5"),
16
+ ]
17
+ )
18
+
19
+ # Define an async function to handle the pipeline
20
+ async def main():
21
+ # Create the pipeline with transformations
22
+ pipeline = IngestionPipeline(
23
+ transformations=[
24
+ SentenceSplitter(chunk_overlap=0),
25
+ HuggingFaceEmbedding(model_name="BAAI/bge-small-en-v1.5"),
26
+ ]
27
+ )
28
+ # Use await inside the async function
29
+ nodes =
30
+ await pipeline.arun(documents=[Document.example()])
31
+ # Optional: Do something with the nodes (e.g., print them)
32
+ print(nodes)
33
+
34
+ # Run the async function using asyncio
35
+ if __name__ == "__main__":
36
+ asyncio.run(main())
37
+
38
+ import chromadb
39
+ from llama_index.vector_stores.chroma import ChromaVectorStore
40
+ from llama_index.core.ingestion import IngestionPipeline
41
+ from llama_index.core.node_parser import SentenceSplitter
42
+ from llama_index.embeddings.huggingface import HuggingFaceEmbedding
43
+
44
+ db = chromadb.PersistentClient(path="./pl_db")
45
+ chroma_collection = db.get_or_create_collection("ppgpl")
46
+ vector_store = ChromaVectorStore(chroma_collection=chroma_collection)
47
+
48
+ pipeline = IngestionPipeline(
49
+ transformations=[
50
+ SentenceSplitter(chunk_size=25, chunk_overlap=0),
51
+ HuggingFaceEmbedding(model_name="BAAI/bge-small-en-v1.5"),
52
+ ],
53
+ vector_store=vector_store,
54
+ )
55
+
56
+
57
+ from llama_index.core import VectorStoreIndex
58
+ from llama_index.embeddings.huggingface import HuggingFaceEmbedding
59
+
60
+ embed_model = HuggingFaceEmbedding(model_name="BAAI/bge-small-en-v1.5")
61
+ index = VectorStoreIndex.from_vector_store(vector_store, embed_model=embed_model)
62
+
63
+ from llama_index.llms.huggingface_api import HuggingFaceInferenceAPI
64
+
65
+ llm = HuggingFaceInferenceAPI(model_name="Qwen/Qwen2.5-Coder-32B-Instruct")
66
+ query_engine = index.as_query_engine(
67
+ llm=llm,
68
+ response_mode="tree_summarize",
69
+ )
70
+ query_engine.query("Солнце на третей ступени")
71
+ # The meaning of life is 42