\r\n          Felix is shocked.\r\n                         \r\n                                                  FELIX\r\n                       What!\r\n                         \r\n                                                  WALKER\r\n                       Yeah, he\'s a Fuckin\' Pig.\r\n                         \r\n                                                  FELIX\r\n                       What\'s his name?\r\n                         \r\n


\r\n                                                  WALKER\r\n                       Phillip Zimmerman.\r\n                         \r\n                                                  FELIX\r\n                       Isn\'t that a Jew name?\r\n                         \r\n                                                  WALKER\r\n                       I don\'t know... probably.\r\n                         \r\n


FELIX\r\n                       So Ron Stallworth is a Fucking Jew.\r\n                         \r\n                                                  WALKER\r\n                       Coulda\' been worse.\r\n                         \r\n          Felix looks at him.\r\n                         \r\n                                                  WALKER (CONT\'D)\r\n                       Coulda\' been a Nigger.\r\n


\r\n          Felix thinks to himself, then looks over at\r\n                         \r\n                         RON\r\n                         \r\n          who is standing not far away from Devin Davis. Ron is\r\n                         WATCHING\r\n                         \r\n                         FELIX\r\n                         \r\n          and Walker focusing on Flip. The Two, Ron and Felix, share a\r\n          long uncomfortable stare. Felix has figured it all out.\r\n                         \r\n


\r\n                                                  FELIX\r\n                       He\'s a Nigger.\r\n                         \r\n          Walker turns to Felix.\r\n                         \r\n                                                  FELIX (CONT\'D)\r\n                       That Cop guarding Davis. Zimmerman is\r\n                       using his name.\r\n                                                    WALKER\r\n                         Let\'s tell Davis.\r\n


Let\'s tell Davis.\r\n                         \r\n          Walker starts to rise, Felix lowers him back.\r\n                         \r\n                                                    FELIX\r\n                         Not now, I\'ll find the moment.\r\n                         \r\n          Felix turns to Connie, whispering, they all then rise. Ron\r\n          knows something is askew. He gives Flip a look. Flip sees it\r\n          as Ron walks over to Davis.\r\n                         \r\n


RON STALLWORTH\r\n                         ...Mr. Davis, a favor to ask.\r\n                         Nobody\'s gonna believe me when I tell\r\n                         them I was your Bodyguard.\r\n                         \r\n          Ron holds up a Polaroid Camera.\r\n                         \r\n                                     RON STALLWORTH (CONT\'D)\r\n                         Care to take a Photo with me?\r\n                         \r\n          Davis laughs, looking around the table.\r\n


table.\r\n                         \r\n                                                    DEVIN DAVIS\r\n                         I don\'t see any harm in that. Hey\r\n                         Jesse... why don\'t you get in here\r\n                         too?\r\n                         \r\n          Jesse Nayyar, equally amused, walks over. Flip is already out\r\n          of his Seat, walking to Ron. Ron glances over seeing\r\n                         \r\n          FELIX, WALKER AND CONNIE AT THE BACK DOOR (RON\'S POV)\r\n


\r\n          Connie has her purse and Walker hands her a gym bag. Felix\r\n          pecks her on the lips. She exits the steakhouse with the gym\r\n          bag.\r\n                         \r\n          CLOSE - RON\r\n                         \r\n          then turns to Flip.\r\n                         \r\n                                                    RON STALLWORTH\r\n                         You mind taking it, Sir?\r\n                         \r\n          ANGLE - ROOM\r\n


\r\n          Flip nods and Ron hands him The Polaroid Camera.\r\n                         \r\n          Ron walks back and stands in between Davis, THE GRAND WIZARD\r\n          and Jesse, THE GRAND DRAGON.\r\n                                                  RON (CONT\'D)\r\n                       One... Two... Three!\r\n                         \r\n          Right as the Camera Flashes, Ron drapes his arms around both\r\n          Davis and Jesse, pulling them in real close. The Polaroid\r\n          clicks and spits out the Photo instantly.\r\n                         \r\n


\r\n          Davis is startled for a brief second... then it all happens\r\n          in a FLASH.\r\n                         \r\n          Davis and Ron spring toward Flip, each making a Mad Dash for\r\n          the Photo. Ron grabs it first. Davis lunges to grab the Photo\r\n          from Ron\'s hands but Ron yanks it away. Davis is up in Ron\'s\r\n          Face.\r\n                         \r\n                                                  DEVIN DAVIS\r\n                       Nigger, What the Fuck did you just\r\n                       do?\r\n


\r\n                                                  RON STALLWORTH\r\n                       If you lay one Finger on me, I\'ll\r\n                       arrest you for assaulting a Police\r\n                       Officer. That\'s worth about Five\r\n                       Years in Prison. Try me. See if I\'m\r\n                       playing.\r\n                         \r\n          The Room falls into Dead Silence. Klansmen mouths hang open,\r\n          watching their Leaders threatened by a DETECTIVE NIGGER.\r\n          Davis gives Ron the most vicious look


Davis gives Ron the most vicious look imaginable.\r\n                         \r\n          Ron stares back. It\'s a SHOWDOWN. Several Men in the Room\r\n          have their hands at their Waists, seconds away from drawing\r\n          their Guns.\r\n                         \r\n          Ron can do only one thing: he smiles.\r\n                         \r\n                                   RON STALLWORTH (CONT\'D)\r\n                       Thanks for the Photo, Mr. Davis. Big\r\n                       Fan. God Bless WHITE AMERICA.\r\n                         \r\n          Davis shakes his Head in


Davis shakes his Head in Disgust.\r\n                         \r\n          Bikers and others surround Ron. Flip looks wary knowing\r\n          something is up. He gets in Ron\'s face, threatening.\r\n                         \r\n                                                  FLIP\r\n                       Boy you get ya\' ass out NOW!\r\n                         \r\n          Ron breaks off from the roomful of disdain cutting through\r\n          the watching Crowd pushing past Bodies heading toward the\r\n          front door. Suddenly, Ron\'s arm is grabbed...\r\n                         \r\n


\r\n                                   FELIX (O.S.)\r\n                       Where\'s your Patrice?\r\n               Ron turns finding Felix holding his arm.\r\n                         \r\n                                                       FELIX\r\n                            Detective Stallworth!\r\n               Ron JERKS his arm away heading to the exit.\r\n                         \r\n              EXT. STEAKHOUSE/PARKING LOT - DAY\r\n                         \r\n               Ron rushes through the Lot


Ron rushes through the Lot hopping in his unmarked Car.\r\n                         \r\n          INT. RON\'S CAR - DAY\r\n               Ron throws the Car into gear. He Yells into his Radio.\r\n                         \r\n                                                       RON STALLWORTH\r\n                            Attention all Units. Be on the\r\n                            lookout for a White Pickup with a\r\n                            "White Pride" Bumper Sticker. License\r\n                            plate: KE-4108.\r\n


\r\n               Ron guns it down the street.\r\n                         \r\n                                                       RON STALLWORTH\r\n                            Request Backup. FREEDOM HOUSE.\r\n                         \r\n               INT. STEAKHOUSE - DAY\r\n                         \r\n               Walker and Felix sit on both sides of Flip. Flip grins at\r\n               them, then does a double take at Walker, who stares at him.\r\n                         \r\n


\r\n                                                       FELIX\r\n                            Ron, I believe you know my friend.\r\n                         \r\n               Flip stares at Walker playing it totally cool.\r\n                         \r\n                                                       FLIP\r\n                            No, I don\'t believe we\'ve ever met.\r\n                         \r\n                                                       WALKER\r\n


WALKER\r\n                            It\'s been a few years.\r\n                         \r\n                                                       FLIP\r\n                            No, sorry, I can\'t place you.\r\n                         \r\n                                                       DEVIN DAVIS\r\n                            Did you Guys go to School together?\r\n                         \r\n


WALKER\r\n                            No, I went to a Private School in\r\n                            Leavenworth, Kansas.\r\n                         \r\n                                                       FELIX\r\n                            Isn\'t that where the Prison is?\r\n                                                         WALKER\r\n                              Matter a fact it is.\r\n                         \r\n               Walker looks at Flip,


Walker looks at Flip, who says nothing.\r\n                         \r\n                                                         FELIX\r\n                              You know something about that. Don\'t\r\n                              you, Flip?\r\n                         \r\n               Felix\'s eyes burn into Flip, who doesn\'t flinch. Suddenly,\r\n               Josh the Waiter interrupts.\r\n                         \r\n                                                         JOSH\r\n


JOSH\r\n                              There\'s an emergency phone call in\r\n                              the Lobby for a -- Felix Kendrickson.\r\n                         \r\n               Felix rises.\r\n                         \r\n                                                         FELIX\r\n                              Don\'t say another word.\r\n                              I\'ll be right back. Flip.\r\n                         \r\n               Felix walks off. Walker watches him leave turning to Flip,\r\n


watches him leave turning to Flip,\r\n               who plays it cool. A confused Davis observes it all.\r\n                         \r\n               EXT. PHONE BOOTH - DAY - INTERCUT\r\n                         \r\n               ANGLE - FREEDOM HOUSE\r\n                         \r\n               Across the street from the Freedom House, a nervous Connie is\r\n               on the phone clearly rattled.\r\n                         \r\n                                                         CONNIE\r\n                              Jesus! They\'ve got Cops


Jesus! They\'ve got Cops everywhere\r\n                              here! Somebody tipped them off.\r\n                         \r\n               A Police Cruiser drives past.\r\n                         \r\n                                                         CONNIE (CONT\'D)\r\n                              My God there goes another one!\r\n                         \r\n          154A INT. STEAKHOUSE - LOBBY - DAY - INTERCUT\r\n                         \r\n               Felix talks to her from the Lobby of The Steakhouse trying


to her from the Lobby of The Steakhouse trying to\r\n               keep their conversation private.\r\n                         \r\n                                                         FELIX\r\n                              All right, calm down, we planned for\r\n                              this. We\'ll go to Plan B. Okay?\r\n                         \r\n                                                         CONNIE\r\n                              Okay... Plan B.\r\n


FELIX\r\n          You can do this. All right. I\'ll be\r\n          right there.\r\n                                                  CONNIE\r\n                       All right... Love You.\r\n                         \r\n          Dial tone. Felix has already hung up. She hangs up.\r\n                         \r\n          INT. STEAK HOUSE/LOBBY - DAY\r\n                         \r\n          Felix eyes Walker at the table with Flip and Davis. Felix\r\n          waves to Walker. Ivanhoe sees Felix and rushes to join them.\r\n


\r\n                                                  WALKER\r\n                       Excuse me Mister Davis.\r\n                         \r\n          Walker reluctantly leaves.\r\n                         \r\n                                                  DEVIN DAVIS\r\n                       What was all that about? And why did\r\n                       he keep calling you Flip?\r\n                         \r\n


FLIP\r\n                       We were in Prison together. Years\r\n                       ago. It\'s an inside joke.\r\n                         \r\n          Davis nods, concerned.\r\n                         \r\n                                                  DEVIN DAVIS\r\n                       I hope everything\'s all right?\r\n                         \r\n                                                  FLIP\r\n                       Yeah, but I think he may have\r\n


but I think he may have\r\n                       violated his Parole. Excuse me...\r\n          Flip stands watching Felix and Gang exit the Steakhouse.\r\n                         \r\n          EXT. ACADEMY BOULEVARD - DAY\r\n          Ron\'s Car weaves in between Traffic driving like crazy.\r\n                         \r\n          EXT. FREEDOM HOUSE - DAY\r\n                         \r\n          Ron zooms up to Freedom House SCREECHING to a stop! The event\r\n          is over. There are a few people outside conversing after the\r\n          event. Ron sees Hakeem and jumps out of the car.\r\n                         \r\n


\r\n                                                  RON STALLWORTH\r\n                       Where\'s Patrice???\r\n                         \r\n                                                  HAKEEM\r\n                       Patrice and Odetta took Mister\r\n                       Hopkins to his Hotel.\r\n                         \r\n          Ron jumps back in his Ride and burns rubber heading to\r\n          Patrice\'s place!\r\n          INT.    IVANHOE\'S CAR - DAY\r\n                         \r\n


\r\n            Ivanhoe speeds toward Patrice\'s House with Felix in the\r\n            passenger seat and Walker hovering over them in the rear.\r\n                         \r\n                           OMITTED\r\n                         \r\n             EXT. PATRICE\'S HOUSE - DAY\r\n                         \r\n            Connie drives up. She sits there for a long moment staring at\r\n            Patrice\'s House. Connie decides. She gets out of the Car\r\n            carrying her purse. She looks like an Avon lady coming to\r\n            call. She walks up on Patrice\'s porch looking around. She\r\n


on Patrice\'s porch looking around. She\r\n                           CAREFULLY SETS\r\n                         \r\n            CLOSE - HER PURSE\r\n                         \r\n            down by a pillar on the porch and slowly removes the Bomb.\r\n            She opens the mailbox to place the Bomb. She nervously flips\r\n            the toggle switch when she sees...\r\n                         \r\n            ANGLE - STREET\r\n                         \r\n            Patrice drives up. Flustered, Connie grabs her purse to put\r\n            the Bomb back inside while looking at Patrice and Odetta\r\n


and Odetta\r\n            getting out of the Car and getting Groceries from the trunk.\r\n                         \r\n            Patrice talks to Odetta, not noticing Connie. Connie quickly\r\n            leaves the porch striding to her car sweating, crazy nervous.\r\n            Patrice and Odetta talk, entering her House.\r\n                         \r\n            CLOSE - CONNIE\r\n                         \r\n            briskly moves toward the rear of Patrice\'s Car.\r\n                         \r\n            ANGLE - STREET\r\n                         \r\n            Ron whips around the corner seeing Connie


Ron whips around the corner seeing Connie through the\r\n            windshield! He SCREECHES to a stop!\r\n                         \r\n            Connie tries to nonchalantly head back to her vehicle.\r\n                         \r\n            Ron jumps out the car yelling!\r\n                         \r\n                                                     RON STALLWORTH\r\n                          CSPD! Stay where you are!\r\n                         \r\n            Connie looks back at Ron, increasing her pace.\r\n                         \r\n


\r\n                                      RON STALLWORTH(CONT\'D)\r\n                          Don\'t move!!!\r\n                         \r\n            Connie breaks into a run. Ron dashes after her grabbing her\r\n            as she opens the Pick Up Truck door.\r\n                                   RON STALLWORTH (CONT\'D)\r\n                       Where\'s that Bomb? Did you place it!\r\n                         \r\n          The Two fight as she SCREAMS, scratching and clawing at Ron.\r\n          The Fight moves from the Pick Up Truck as he throws her down\r\n          on the grass


her down\r\n          on the grass of a near by lawn, subduing the SCREAMING\r\n          Connie.\r\n                         \r\n                                   RON STALLWORTH (CONT\'D)\r\n                       Where is it!!!\r\n                         \r\n          Ron reaches back for his handcuffs...\r\n                         \r\n                                      CSPD OFFICER BRICKHOUSE\r\n                       Freeze!\r\n                         \r\n          Ron looks right and OFFICER BRICKHOUSE has his Gun pointed at\r\n


his Gun pointed at\r\n          him. Then looks left finding OFFICER MYERS, also White, 30\'s,\r\n          has his revolver aimed at him.\r\n                         \r\n                                      CSPD OFFICER BRICKHOUSE (CONT\'D)\r\n                       Get off her!\r\n                         \r\n          Ron slowly rises up off Connie, gradually turning to them.\r\n          With his hands raised you can see Ron\'s shoulder holster and\r\n          38 CALIBER SNUB-NOSE. Officer Myers sees it!\r\n                         \r\n                                   CSPD OFFICER


CSPD OFFICER MYERS\r\n                       He\'s got a Gun!\r\n                         \r\n                                                  RON STALLWORTH\r\n                       I\'m a Cop! I\'m a COP!!!\r\n                         \r\n          Connie springs up from the lawn! Pleading like crazy to the\r\n          cops!\r\n                         \r\n                                                  CONNIE\r\n                       He attacked me! That Nigger attacked\r\n


That Nigger attacked\r\n                       me, he tried to Rape me! Arrest him!\r\n                         \r\n          Myers and Brickhouse look at each other, unsure.\r\n                         \r\n                                                  RON STALLWORTH\r\n                       I\'m Undercover!!!\r\n                         \r\n                                   CSPD OFFICER BRICKHOUSE\r\n                       Show me your badge!\r\n                         \r\n          Ron goes to reach in his pocket but the two Officers


to reach in his pocket but the two Officers make\r\n          aggressive moves with their Guns! Ron catches himself! He\r\n          doesn\'t want to get shot! He decides to just tell them.\r\n                         \r\n                                                  RON STALLWORTH\r\n                       It\'s in my pocket.\r\n                                                  CONNIE\r\n                       You gonna believe this lying Nigger\r\n                       or me?\r\n                         \r\n


CSPD OFFICER MYERS\r\n                       Get on the ground!\r\n                         \r\n                                                  RON STALLWORTH\r\n                       I\'m a Cop goddammit! She\'s got a\r\n                       Bomb! She\'s a Terrorist!\r\n                         \r\n                                   CSPD OFFICER MYERS\r\n                       Get on the ground NOW!!!\r\n                         \r\n          Ron slowly lowers down to his knees and


Ron slowly lowers down to his knees and the two Cops push him\r\n          face down on the street! Felix drives up with Ivanhoe and\r\n          Walker in the back seat.\r\n                         \r\n          ANGLE - STREET\r\n          Felix has pulled up next to Patrice\'s Volkswagen Beetle.\r\n                         \r\n          INT./EXT. CAR - DAY\r\n                         \r\n                                                  FELIX\r\n                       Gimme\' a detonator.\r\n                         \r\n          Walker unzips his Bag quickly handing a


Walker unzips his Bag quickly handing a Detonator to Felix.\r\n                         \r\n          ANGLE - DOWN THE STREET\r\n                         \r\n          Ron yells at the Cops trying to explain!\r\n                         \r\n                                                  RON STALLWORTH\r\n                       THAT WOMAN HAS A BOMB SHE\'S TRYING TO\r\n                       BLOW THAT HOUSE UP!\r\n                         \r\n          ANGLE - PATRICE\'S HOUSE\r\n                         \r\n          Patrice hearing the


\r\n          Patrice hearing the commotion steps out on the porch with\r\n          Odetta.\r\n                         \r\n          Ivanhoe sees Patrice on the porch.\r\n                         \r\n                                                  IVANHOE\r\n                       There she is! Do it!\r\n                         \r\n          ANGLE - DOWN THE STREET\r\n                         \r\n                                                   RON STALLWORTH\r\n                       PATRICE!\r\n


PATRICE!\r\n                         \r\n          Officer Myers jabs Ron in the Belly with his Nightstick. Ron\r\n          doubles over.\r\n          CLOSE - PATRICE\r\n                         \r\n                                                     PATRICE\r\n                          Ron???\r\n                         \r\n          CLOSE - FELIX\r\n                         \r\n                                                     FELIX\r\n                          You\'re Dead Black Bitch.\r\n


You\'re Dead Black Bitch.\r\n                         \r\n          ANGLE - PATRICE\'S HOUSE\r\n                         \r\n          Patrice looks at Felix.\r\n                         \r\n          CLOSE - RON\r\n                         \r\n          recovering from the blow SCREAMS to her!\r\n                         \r\n                                                     RON STALLWORTH\r\n                          RUN!!! RUN!!! RUN!!!\r\n                         \r\n          ANGLE - STREET\r\n


ANGLE - STREET\r\n                         \r\n          Connie finally sees Felix in the car. Felix sees her, nods.\r\n          She then sees that they are parked... NEXT TO PATRICE\'S\r\n          CAR!!! Connie runs to Felix, screaming!\r\n                         \r\n                                                     CONNIE\r\n                          NO!!! FELIX!!! NO!!! FELIX!!!\r\n                         \r\n          Felix pushes the Button!\r\n                         \r\n                         THE BOMB\r\n


\r\n          is attached to the inside of the wheel well of Patrice\'s car.\r\n                         \r\n                         PATRICE\'S CAR\r\n                         \r\n          EXPLODES! THEN IT BLOWS UP FELIX\'S CAR NEXT TO IT!!! A double\r\n          explosion!!! THE IMPACT BLOWS OUT WINDOWS EVERYWHERE! Patrice\r\n          and Odetta are knocked to the ground. Connie is hurled to the\r\n          street! Glass and car parts flying! Ron and the Cops are\r\n          ROCKED by the force of the HUGE BLAST!\r\n                         \r\n          THE TWO CARS TOTALLY DESTROYED!


THE TWO CARS TOTALLY DESTROYED! ENGULFED IN FLAMES!!!\r\n                         \r\n          Connie on her knees on the street, weeping!\r\n                         \r\n          RON STILL HANDCUFFED\r\n                         \r\n          through the smoke and flames is able to make eye contact with\r\n          Patrice, on the steps of her porch. She is shaken but all\r\n          right. SIRENS in the distance heading toward them!\r\n                         \r\n          ANGLE - STREET\r\n          Flip drives up in a fury and jumps out and holds up his\r\n          BADGE.\r\n


\r\n                                                  FLIP\r\n                       Hey, you fucking idiots!!! We\'re\r\n                       undercover.\r\n                         \r\n          Officers Brickhouse and Myers lower their guns.\r\n                         \r\n          CLOSE - RON STALLWORTH\r\n                         \r\n                                                   RON STALLWORTH\r\n              YOU\'RE LATE.\r\n                         \r\n              CLOSE


\r\n              CLOSE - FLIP\r\n              Flip smiles.\r\n                         \r\n                               OMITTED\r\n                         \r\n                               OMITTED\r\n          INT. DIVE BAR - NIGHT\r\n                         \r\n          The place is full of Off Duty Cops and their Girlfriends, a\r\n          few Wives but mainly Cops drinking and having a good time.\r\n          Ron is in the corner talking with Patrice. They are sharing a\r\n          drink looking very intimate. Ron sees something.\r\n                         \r\n


\r\n                                                  RON STALLWORTH\r\n                       Jeezus Christ.\r\n                         \r\n                                                   PATRICE\r\n                       What?\r\n                         \r\n                                                  RON STALLWORTH\r\n                       Your Boyfriend.\r\n                         \r\n          Patrice turns and sees.\r\n


\r\n                                                   PATRICE\r\n                       Oh My God.\r\n                         \r\n          Master Patrolman Landers nears them with a Beer in his hand.\r\n                         \r\n                                                  LANDERS\r\n                       Who\'s da\' Soul Sistah, Stallworth?\r\n                       You been holding out on me.\r\n                         \r\n          Patrice stares at him with contempt.\r\n


stares at him with contempt.\r\n                         \r\n                                                  PATRICE\r\n                       You don\'t remember me do you?\r\n                         \r\n          Landers stares at her.\r\n                                                    PATRICE (CONT\'D)\r\n                       Kwame Ture.\r\n                         \r\n          Landers doesn\'t know who that is.\r\n                         \r\n


PATRICE (CONT\'D)\r\n                       Stokely Carmichael.\r\n                         \r\n                                                  LANDERS\r\n                       Oh Yeah, Yeah, you looked good that\r\n                       night but you look even better now.\r\n                         \r\n                                                  PATRICE\r\n                       How often do you do that to Black\r\n                       People?\r\n


\r\n                                                    LANDERS\r\n                       Do what?\r\n                         \r\n                                                  PATRICE\r\n                       Pull us over for nothing. Harass us.\r\n                       Put your hands all over a Woman in\r\n                       the guise of searching her. Call us\r\n                       everything but A Child of God.\r\n                         \r\n


LANDERS\r\n                       I don\'t know what you\'re talking\r\n                       about.\r\n                         \r\n                                                  RON STALLWORTH\r\n                       It\'s like what I told you. He just\r\n                       likes taking advantage but in the end\r\n                       he\'s All Hat and No Cattle.\r\n                         \r\n          Landers looks around then leans in close to Patrice and Ron.\r\n


to Patrice and Ron.\r\n          He speaks softly issuing a deadly threat.\r\n                         \r\n                                                  LANDERS\r\n                       Let me tell you both something, I\'ve\r\n                       been keeping you People in line in\r\n                       this City for years. What I did to\r\n                       your Girl that night, I can do to any\r\n                       of you, Anytime, Anyplace. That\'s my\r\n                       prerogative. I can even Bust a Cap in\r\n                       ya Black


ya Black Ass if I feel like it and\r\n                       nuthin\' will be done about it. Get\r\n                       it? Wish the both of you got blown up\r\n                       instead of Good White Folks.\r\n                         \r\n          Master Patrolman Landers raises up.\r\n                         \r\n                                                  RON STALLWORTH\r\n                       Ohhh, I get it.\r\n                         \r\n          Ron looks at Patrice.\r\n


RON STALLWORTH (CONT\'D)\r\n                       You get it, Patrice?\r\n                         \r\n                                                  PATRICE\r\n                       Oh, I totally and completely get it.\r\n                         \r\n          Landers looks confused with their response.\r\n                         \r\n                                                  RON STALLWORTH\r\n                       Good.\r\n                         \r\n


\r\n          Ron turns toward the Bar and shouts.\r\n                         \r\n                                   RON STALLWORTH (CONT\'D)\r\n                       You get it, Flip?\r\n                         \r\n          Behind the Bar, Flip leans out from the back room waving to\r\n          Ron wearing Headphones recording The Conversation.\r\n                         \r\n                                                  FLIP\r\n                       Oh, We got it! We got it all!\r\n                         \r\n


\r\n          Ron stands removing his Shirt revealing The Wire he is\r\n          wearing. Master Patrolman Landers is in shock.\r\n                         \r\n                                                  RON STALLWORTH\r\n                       You get it, Chief?\r\n                         \r\n          Sgt. Trapp appears taking the Beer from Landers\' hand turning\r\n          him around putting Handcuffs on him. Chief Bridges comes from\r\n          the back nearing Landers. The two lock eyes.\r\n                         \r\n


CHIEF BRIDGES\r\n                       Oh, I really, really get it. You\'re\r\n                       under arrest for Police Misconduct,\r\n                       Sexual Misconduct and Police\r\n                       Brutality.\r\n                         \r\n          Sgt. Trapp and the Chief usher Master Patrolman Landers, who\r\n          is babbling like a Fool out of The Bar reading him his\r\n          rights.\r\n                         \r\n          INT. INTELLIGENCE UNIT - CSPD - DAY\r\n                         \r\n          Ron, walking taller


\r\n          Ron, walking taller than usual, steps inside The Unit. Some\r\n          of his Colleagues notice and give him a Low-Key Ovation. At\r\n          his Desk is Flip, who is in Great Spirits.\r\n                         \r\n                                                  FLIP\r\n                       There he is... Man of the Minute.\r\n                         \r\n                                                  RON STALLWORTH\r\n                       ... not an Hour?\r\n                         \r\n          Ron smiles, gives Fives all around.


Ron smiles, gives Fives all around. They all share a laugh.\r\n                                                   FLIP (CONT\'D)\r\n                        That Polaroid Stunt you pulled? When\r\n                        you threw your Arms around them, I\r\n                        swear to God I almost Shit myself!\r\n                         \r\n                                                   RON STALLWORTH\r\n                        Told you, Ron was born ready.\r\n                         \r\n


FLIP\r\n                        Born ready is Ron.\r\n                         \r\n          Sgt. Trapp steps out of his Office.\r\n                         \r\n                                    SGT. TRAPP\r\n                        There\'s The Crazy Son of a Bitch!!!\r\n                         \r\n          Trapp gives Ron a Bear Hug.\r\n                         \r\n                                    SGT. TRAPP (CONT\'D)\r\n


You did good.\r\n                         \r\n                                                   RON STALLWORTH\r\n                        Sarge. We did good.\r\n                         \r\n          Ron and Flip eyes meet, bonded.\r\n                         \r\n                                    SGT. TRAPP\r\n                        Chief wants to see you Guys.\r\n                         \r\n          Flip nudges Ron.\r\n                         \r\n


\r\n                                                   FLIP\r\n                        Hey... early promotion?\r\n                         \r\n          Ron smiles.\r\n                         \r\n          INT. OFFICE OF THE CHIEF OF POLICE - DAY\r\n                         \r\n          Ron, Flip, and Sgt. Trapp sit opposite Chief Bridges.\r\n                         \r\n                                                   CHIEF BRIDGES\r\n                        Again, I can\'t commend you enough for\r\n


I can\'t commend you enough for\r\n                        what you\'ve achieved. You know there\r\n                        was not a Single Cross Burning the\r\n                        entire time you were involved?\r\n                         \r\n                                                    RON STALLWORTH\r\n                        I\'m aware.\r\n                         \r\n                                                   CHIEF BRIDGES\r\n                        But all good things must come to an\r\n


end...\r\n                         \r\n          Sgt. Trapp shakes his head, resigned.\r\n                                                  RON STALLWORTH\r\n                       What does that mean?\r\n                         \r\n          Ron and Flip look at each other, stunned.\r\n                         \r\n                                                     CHIEF BRIDGES\r\n                       Budget Cuts.\r\n                         \r\n


FLIP\r\n                       Budget Cuts?\r\n                         \r\n                                                  CHIEF BRIDGES\r\n                       Inflation... I wish I had a choice.\r\n                       My hands are tied. Besides, it looks\r\n                       like there are no longer any tangible\r\n                       Threats...\r\n                         \r\n                                                  RON


RON STALLWORTH\r\n                       ...Sounds like we did too good a job.\r\n                         \r\n                                                  CHIEF BRIDGES\r\n                       Not a Bad Legacy to leave.\r\n                         \r\n          Bridges takes a deliberate pause. Then, THE Sucker Punch...\r\n                         \r\n                                   CHIEF BRIDGES (CONT\'D)\r\n                       And I need you, Ron Stallworth, to\r\n                       destroy all


destroy all Evidence of this\r\n                       Investigation.\r\n                         \r\n                                                     RON STALLWORTH\r\n                       Excuse me?\r\n                         \r\n                                                  FLIP\r\n                       This is total Horseshit.\r\n                         \r\n                                                  CHIEF BRIDGES\r\n                       We


We prefer that The Public never knew\r\n                       about this Investigation.\r\n                         \r\n          Ron and Flip are heated. Sgt. Trapp is silent but gutted.\r\n                         \r\n                                                  RON STALLWORTH\r\n                       If they found out...\r\n                         \r\n                                                  CHIEF BRIDGES\r\n                       ...Cease all further contact with The\r\n


Ku Klux Klan. Effective immediately.\r\n                       That goes for Flip too. Ron\r\n                       Stallworth...\r\n                         \r\n                                                  RON STALLWORTH\r\n                       This is some Fucked up Bullshit.\r\n                                                  CHIEF BRIDGES\r\n                       Take a week off. Go on vacation with\r\n                       your Girlfriend. We\'ll hold down The\r\n                       Fort until you get


Fort until you get back. Get you\r\n                       another assignment...Narcotics.\r\n                         \r\n          Ron storms out.\r\n                         \r\n          INT. INTELLIGENCE UNIT - CSPD - DAY\r\n                         \r\n          Ron reflects as he feeds Investigation documents in a\r\n          Shredder. The documents shred into pieces. Just then, the\r\n          Undercover Phone Line rings on Ron\'s desk.\r\n                         \r\n          Ron stares at the Phone, still ringing. He looks at The\r\n          Documents in his hand, about to feed them into The Shredder.\r\n          Ron


The Shredder.\r\n          Ron stops. Throws The Documents in a Folder. Sweeps some\r\n          Folders into his Briefcase. Leaves as The Phone still rings.\r\n                         \r\n          EXT. COLORADO SPRINGS POLICE DEPARTMENT BUILDING - DAY\r\n                         \r\n          Ron is walking fast now, trying to make it out of The\r\n          Building with The Evidence but he remembers something.\r\n          He stops, turns back.\r\n                         \r\n          INT. INTELLIGENCE DIVISION - CSPD - DAY\r\n                         \r\n          Ron sits at his Desk, on The Undercover Phone Line. Flip,\r\n          Jimmy and Sgt. Trapp are


Jimmy and Sgt. Trapp are behind, both close enough to listen,\r\n          giggling.\r\n                         \r\n                                                  RON STALLWORTH\r\n                       I\'m sorry we didn\'t get to spend more\r\n                       One-on-One time together.\r\n                         \r\n          INT. DEVIN DAVIS OFFICE - DAY\r\n                         \r\n          INTERCUT RON, FLIP, AND TRAPP WITH DEVIN DAVIS:\r\n                         \r\n


DEVIN DAVIS\r\n                       Well, that tragic event. I had just\r\n                       met those Fine Brothers in the cause.\r\n                         \r\n                                                  RON STALLWORTH\r\n                       Our Chapter is just shaken to the\r\n                       core. And poor Connie not only does\r\n                       she lose her Husband but she\'s facing\r\n                       a healthy Prison Sentence.\r\n                         \r\n


\r\n                                                  DEVIN DAVIS\r\n                       My God. And then there was that one\r\n                       Nigger Detective who threatened me.\r\n                                                  RON STALLWORTH\r\n                       Goddamn Coloreds sure know how to\r\n                       spoil a Celebration.\r\n                         \r\n          Flip and Jimmy snort. Ron holds in a Belly-Laugh.\r\n                         \r\n


DEVIN DAVIS\r\n                       Christ. You can say that again.\r\n                         \r\n          Ron cracks up into his Hand. Sgt. Trapp is wheezing-- his\r\n          Face Bright Pink. Flip is laughing hard in the background.\r\n                         \r\n                                                  RON STALLWORTH\r\n                       Can I ask you something? That Nigger\r\n                       Detective who gave you a hard time?\r\n                       Ever get his name?\r\n


\r\n                                                    DEVIN DAVIS\r\n                       No, I...\r\n                         \r\n                                                  RON STALLWORTH\r\n                       ...Are-uh you sure you don\'t know who\r\n                       he is? Are-uh you absolutely sure?\r\n                         \r\n          Davis looks at his Phone. Ron takes out his SMALL NOTE PAD\r\n          out revealing a list of Racial epitaphs he had written down\r\n          being on this


written down\r\n          being on this Investigation. He reads from it to Davis on the\r\n          phone.\r\n                         \r\n          ANGLE - SPLIT SCREEN\r\n                         \r\n          Ron Stallworth and Devin Davis.\r\n                         \r\n                                   RON STALLWORTH (CONT\'D)\r\n                       Cuz\' dat Niggah Coon, Gator Bait,\r\n                       Spade, Spook, Sambo, Spear Flippin\',\r\n                       Jungle Bunny, Mississippi Wind\r\n                       Chime...Detective is Ron Stallworth\r\n


is Ron Stallworth\r\n                       you Redneck, Racist Peckerwood Small\r\n                       Dick Motherfucker!!!\r\n                         \r\n          CLICK. Ron SLAM DUNKS THE RECEIVER LIKE SHAQ.\r\n                         \r\n          CLOSE - DEVIN DAVIS\r\n                         \r\n          Devin Davis\'s Jaw Drops.\r\n                         \r\n          INT. INTELLIGENCE DIVISION - CSPD - DAY\r\n                         \r\n          THE WHOLE OFFICE EXPLODES IN LAUGHTER. COPS ARE ROLLING ON\r\n          THE OFFICE FLOOR.\r\n          INT.


OFFICE FLOOR.\r\n          INT. RON\'S APARTMENT - KITCHEN - NIGHT\r\n                         \r\n          Folders of Evidence sit on The Kitchen Table in a stack in\r\n          front of Ron. He sips his Lipton Tea and removes from the\r\n                         FILES THE\r\n                         \r\n          CLOSE - POLAROID\r\n          Ron hugged up, between Devin Davis and Jesse Nayyar. He then\r\n          looks at The Klan Membership Card shifting in his hands, his\r\n          gaze fixated on the words.\r\n                         \r\n          CLOSE - Ron Stallworth\r\n          KKK Member in Good Standing\r\n


Member in Good Standing\r\n                         \r\n          Patrice comes up from behind.\r\n          CLOSE - PATRICE\r\n          She pulls out a small handgun from her pocketbook.\r\n                         \r\n          2 - SHOT - PATRICE AND RON\r\n                         \r\n                                   PATRICE (O.S.)\r\n                       Have you Resigned from The KKK?\r\n                         \r\n                                                     RON STALLWORTH\r\n                       Affirmative.\r\n


Affirmative.\r\n                         \r\n                                                  PATRICE\r\n                       Have you handed in your Resignation\r\n                       as a Undercover Detective for The\r\n                       Colorado Springs Police Department?\r\n                         \r\n                                                  RON STALLWORTH\r\n                       Negative. Truth be told I\'ve always\r\n                       wanted to be a Cop...and I\'m still\r\n                       for The


for The Liberation for My People.\r\n                         \r\n                                                  PATRICE\r\n                       My Conscience won\'t let me Sleep with\r\n                       The Enemy.\r\n                         \r\n                                                  RON STALLWORTH\r\n                       Enemy? I\'m a Black Man that saved\r\n                       your life.\r\n                         \r\n


PATRICE\r\n                       You\'re absolutely right, and I Thank\r\n                       you for it.\r\n                         \r\n          Patrice Kisses Ron on the cheek. Good Bye. WE HEAR a KNOCK on\r\n          Ron\'s DOOR. Ron, who is startled, slowly rises. We HEAR\r\n          another KNOCK.\r\n                         \r\n          QUICK FLASHES - of a an OLD TIME KLAN RALLY. Ron moves\r\n          quietly to pull out his SERVICE REVOLVER from the COUNTER\r\n          DRAWER. WE HEAR ANOTHER KNOCK on the DOOR. Patrice stands\r\n          behind


Patrice stands\r\n          behind him.\r\n                         \r\n          QUICK FLASHES - BLACK BODY HANGING FROM A TREE (STRANGE\r\n          FRUIT) Ron slowly moves to the DOOR. Ron has his SERVICE\r\n          REVOLVER up and aimed ready to fire. Ron swings open the\r\n          DOOR.\r\n          ANGLE - HALLWAY\r\n                         \r\n          CU - RON\'S POV\r\n                         \r\n          WE TRACK DOWN THE EMPTY HALLWAY PANNING OUT THE WINDOW.\r\n                         \r\n          CLOSE - RON AND PATRICE\r\n                         \r\n          Looking in


\r\n          Looking in the distance: The Rolling Hills surrounding The\r\n          Neighborhood lead towards Pike\'s Peak, which sits on the\r\n          horizon like a King on A Throne.\r\n                         \r\n          WE SEE: Something Burning.\r\n                         \r\n          CLOSER-- WE SEE a CROSS, its Flames dancing, sending embers\r\n          into The BLACK, Colorado Sky.\r\n                         OMITTED\r\n                         \r\n          EXT. UVA CAMPUS - NIGHT\r\n                         \r\n          WE SEE FOOTAGE of NEO-NAZIS, ALT RIGHT, THE KLAN, NEO-\r\n


ALT RIGHT, THE KLAN, NEO-\r\n          CONFEDERATES AND WHITE NATIONALISTS MARCHING, HOLDING UP\r\n          THEIR TIKI TORCHES, CHANTING.\r\n                         \r\n                                                  AMERICAN TERRORISTS\r\n                       YOU WILL NOT REPLACE US!!!\r\n                       JEWS WILL NOT REPLACE US!!!\r\n                       BLOOD AND SOIL!!!\r\n                         \r\n                                                     CUT TO BLACK.\r\n                         \r\n


\r\n                                    FINI.\r\n\r\n\r\n\n\n\n\nBlacKkKlansman\nWriters : \xa0\xa0Charlie Wachtel\xa0\xa0David Rabinowitz\xa0\xa0Kevin Willmott\xa0\xa0Spike Lee\nGenres : \xa0\xa0Crime\xa0\xa0Drama\nUser Comments\n\n\n\n\n\r\nBack to IMSDb\n\n\n', lookup_str='', metadata={'source': 'https://imsdb.com/scripts/BlacKkKlansman.html'}, lookup_index=0)]


previous
Image captions
next
Markdown
By Harrison Chase

      © Copyright 2023, Harrison Chase.

  Last updated on Apr 25, 2023.


.ipynb
.pdf
Azure Blob Storage Container
 Contents
Specifying a prefix
Azure Blob Storage Container#
This covers how to load document objects from a container on Azure Blob Storage.
from langchain.document_loaders import AzureBlobStorageContainerLoader
#!pip install azure-storage-blob
loader = AzureBlobStorageContainerLoader(conn_str="<conn_str>", container="<container>")
loader.load()
[Document(page_content='Lorem ipsum dolor sit amet.', lookup_str='', metadata={'source': '/var/folders/y6/8_bzdg295ld6s1_97_12m4lr0000gn/T/tmpaa9xl6ch/fake.docx'}, lookup_index=0)]
Specifying a prefix#
You can also specify a prefix for more finegrained control over what files to load.
loader = AzureBlobStorageContainerLoader(conn_str="<conn_str>", container="<container>", prefix="<prefix>")
loader.load()
[Document(page_content='Lorem ipsum dolor sit amet.', lookup_str='', metadata={'source': '/var/folders/y6/8_bzdg295ld6s1_97_12m4lr0000gn/T/tmpujbkzf_l/fake.docx'}, lookup_index=0)]
previous
AZLyrics
next
Azure Blob Storage File
 Contents

Specifying a prefix
By Harrison Chase

      © Copyright 2023, Harrison Chase.

  Last updated on Apr 25, 2023.


.ipynb
.pdf
Sitemap Loader
 Contents
Filtering sitemap URLs
Sitemap Loader#
Extends from the WebBaseLoader, this will load a sitemap from a given URL, and then scrape and load all the pages in the sitemap, returning each page as a document.
The scraping is done concurrently, using WebBaseLoader.  There are reasonable limits to concurrent requests, defaulting to 2 per second.  If you aren’t concerned about being a good citizen, or you control the server you are scraping and don’t care about load, you can change the requests_per_second parameter to increase the max concurrent requests.  Note, while this will speed up the scraping process, but may cause the server to block you.  Be careful!
!pip install nest_asyncio
Requirement already satisfied: nest_asyncio in /Users/tasp/Code/projects/langchain/.venv/lib/python3.10/site-packages (1.5.6)
[notice] A new release of pip available: 22.3.1 -> 23.0.1
[notice] To update, run: pip install --upgrade pip
# fixes a bug with asyncio and jupyter
import nest_asyncio
nest_asyncio.apply()
from langchain.document_loaders.sitemap import SitemapLoader
sitemap_loader = SitemapLoader(web_path="https://langchain.readthedocs.io/sitemap.xml")
docs = sitemap_loader.load()
docs[0]


Document(page_content='\n\n\n\n\n\nWelcome to LangChain — 🦜🔗 LangChain 0.0.123\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nSkip to main content\n\n\n\n\n\n\n\n\n\n\nCtrl+K\n\n\n\n\n\n\n\n\n\n\n\n\n🦜🔗 LangChain 0.0.123\n\n\n\nGetting Started\n\nQuickstart Guide\n\nModules\n\nPrompt Templates\nGetting Started\nKey Concepts\nHow-To Guides\nCreate a custom prompt template\nCreate a custom example selector\nProvide few shot examples to a prompt\nPrompt Serialization\nExample Selectors\nOutput Parsers\n\n\nReference\nPromptTemplates\nExample Selector\n\n\n\n\nLLMs\nGetting Started\nKey Concepts\nHow-To Guides\nGeneric Functionality\nCustom LLM\nFake LLM\nLLM Caching\nLLM Serialization\nToken Usage Tracking\n\n\nIntegrations\nAI21\nAleph Alpha\nAnthropic\nAzure OpenAI LLM Example\nBanana\nCerebriumAI LLM Example\nCohere\nDeepInfra LLM Example\nForefrontAI LLM Example\nGooseAI LLM Example\nHugging Face Hub\nManifest\nModal\nOpenAI\nPetals LLM Example\nPromptLayer OpenAI\nSageMakerEndpoint\nSelf-Hosted Models via


OpenAI\nSageMakerEndpoint\nSelf-Hosted Models via Runhouse\nStochasticAI\nWriter\n\n\nAsync API for LLM\nStreaming with LLMs\n\n\nReference\n\n\nDocument Loaders\nKey Concepts\nHow To Guides\nCoNLL-U\nAirbyte JSON\nAZLyrics\nBlackboard\nCollege Confidential\nCopy Paste\nCSV Loader\nDirectory Loader\nEmail\nEverNote\nFacebook Chat\nFigma\nGCS Directory\nGCS File Storage\nGitBook\nGoogle Drive\nGutenberg\nHacker News\nHTML\niFixit\nImages\nIMSDb\nMarkdown\nNotebook\nNotion\nObsidian\nPDF\nPowerPoint\nReadTheDocs Documentation\nRoam\ns3 Directory\ns3 File\nSubtitle Files\nTelegram\nUnstructured File Loader\nURL\nWeb Base\nWord Documents\nYouTube\n\n\n\n\nUtils\nKey Concepts\nGeneric Utilities\nBash\nBing Search\nGoogle Search\nGoogle Serper API\nIFTTT WebHooks\nPython REPL\nRequests\nSearxNG Search API\nSerpAPI\nWolfram Alpha\nZapier Natural Language Actions API\n\n\nReference\nPython REPL\nSerpAPI\nSearxNG Search\nDocstore\nText Splitter\nEmbeddings\nVectorStores\n\n\n\n\nIndexes\nGetting Started\nKey Concepts\nHow To Guides\nEmbeddings\nHypothetical Document Embeddings\nText Splitter\nVectorStores\nAtlasDB\nChroma\nDeep


Document Embeddings\nText Splitter\nVectorStores\nAtlasDB\nChroma\nDeep Lake\nElasticSearch\nFAISS\nMilvus\nOpenSearch\nPGVector\nPinecone\nQdrant\nRedis\nWeaviate\nChatGPT Plugin Retriever\nVectorStore Retriever\nAnalyze Document\nChat Index\nGraph QA\nQuestion Answering with Sources\nQuestion Answering\nSummarization\nRetrieval Question/Answering\nRetrieval Question Answering with Sources\nVector DB Text Generation\n\n\n\n\nChains\nGetting Started\nHow-To Guides\nGeneric Chains\nLoading from LangChainHub\nLLM Chain\nSequential Chains\nSerialization\nTransformation Chain\n\n\nUtility Chains\nAPI Chains\nSelf-Critique Chain with Constitutional AI\nBashChain\nLLMCheckerChain\nLLM Math\nLLMRequestsChain\nLLMSummarizationCheckerChain\nModeration\nPAL\nSQLite example\n\n\nAsync API for Chain\n\n\nKey Concepts\nReference\n\n\nAgents\nGetting Started\nKey Concepts\nHow-To Guides\nAgents and Vectorstores\nAsync API for Agent\nConversation Agent (for Chat Models)\nChatGPT Plugins\nCustom Agent\nDefining Custom Tools\nHuman as a tool\nIntermediate Steps\nLoading from LangChainHub\nMax Iterations\nMulti Input Tools\nSearch Tools\nSerialization\nAdding SharedMemory to an Agent and its Tools\nCSV Agent\nJSON Agent\nOpenAPI Agent\nPandas Dataframe Agent\nPython


Agent\nJSON Agent\nOpenAPI Agent\nPandas Dataframe Agent\nPython Agent\nSQL Database Agent\nVectorstore Agent\nMRKL\nMRKL Chat\nReAct\nSelf Ask With Search\n\n\nReference\n\n\nMemory\nGetting Started\nKey Concepts\nHow-To Guides\nConversationBufferMemory\nConversationBufferWindowMemory\nEntity Memory\nConversation Knowledge Graph Memory\nConversationSummaryMemory\nConversationSummaryBufferMemory\nConversationTokenBufferMemory\nAdding Memory To an LLMChain\nAdding Memory to a Multi-Input Chain\nAdding Memory to an Agent\nChatGPT Clone\nConversation Agent\nConversational Memory Customization\nCustom Memory\nMultiple Memory\n\n\n\n\nChat\nGetting Started\nKey Concepts\nHow-To Guides\nAgent\nChat Vector DB\nFew Shot Examples\nMemory\nPromptLayer ChatOpenAI\nStreaming\nRetrieval Question/Answering\nRetrieval Question Answering with Sources\n\n\n\n\n\nUse Cases\n\nAgents\nChatbots\nGenerate Examples\nData Augmented Generation\nQuestion Answering\nSummarization\nQuerying Tabular Data\nExtraction\nEvaluation\nAgent Benchmarking: Search + Calculator\nAgent VectorDB Question Answering Benchmarking\nBenchmarking Template\nData Augmented Question Answering\nUsing Hugging Face Datasets\nLLM Math\nQuestion Answering Benchmarking: Paul Graham Essay\nQuestion Answering Benchmarking: State of the Union Address\nQA Generation\nQuestion Answering\nSQL Question Answering Benchmarking:


Generation\nQuestion Answering\nSQL Question Answering Benchmarking: Chinook\n\n\nModel Comparison\n\nReference\n\nInstallation\nIntegrations\nAPI References\nPrompts\nPromptTemplates\nExample Selector\n\n\nUtilities\nPython REPL\nSerpAPI\nSearxNG Search\nDocstore\nText Splitter\nEmbeddings\nVectorStores\n\n\nChains\nAgents\n\n\n\nEcosystem\n\nLangChain Ecosystem\nAI21 Labs\nAtlasDB\nBanana\nCerebriumAI\nChroma\nCohere\nDeepInfra\nDeep Lake\nForefrontAI\nGoogle Search Wrapper\nGoogle Serper Wrapper\nGooseAI\nGraphsignal\nHazy Research\nHelicone\nHugging Face\nMilvus\nModal\nNLPCloud\nOpenAI\nOpenSearch\nPetals\nPGVector\nPinecone\nPromptLayer\nQdrant\nRunhouse\nSearxNG Search API\nSerpAPI\nStochasticAI\nUnstructured\nWeights & Biases\nWeaviate\nWolfram Alpha Wrapper\nWriter\n\n\n\nAdditional Resources\n\nLangChainHub\nGlossary\nLangChain Gallery\nDeployments\nTracing\nDiscord\nProduction Support\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n.rst\n\n\n\n\n\n\n\n.pdf\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nWelcome to LangChain\n\n\n\n\n Contents \n\n\n\nGetting Started\nModules\nUse Cases\nReference Docs\nLangChain Ecosystem\nAdditional


Started\nModules\nUse Cases\nReference Docs\nLangChain Ecosystem\nAdditional Resources\n\n\n\n\n\n\n\n\nWelcome to LangChain#\nLarge language models (LLMs) are emerging as a transformative technology, enabling\ndevelopers to build applications that they previously could not.\nBut using these LLMs in isolation is often not enough to\ncreate a truly powerful app - the real power comes when you are able to\ncombine them with other sources of computation or knowledge.\nThis library is aimed at assisting in the development of those types of applications. Common examples of these types of applications include:\n❓ Question Answering over specific documents\n\nDocumentation\nEnd-to-end Example: Question Answering over Notion Database\n\n💬 Chatbots\n\nDocumentation\nEnd-to-end Example: Chat-LangChain\n\n🤖 Agents\n\nDocumentation\nEnd-to-end Example: GPT+WolframAlpha\n\n\nGetting Started#\nCheckout the below guide for a walkthrough of how to get started using LangChain to create an Language Model application.\n\nGetting Started Documentation\n\n\n\n\n\nModules#\nThere are several main modules that LangChain provides support for.\nFor each module we provide some examples to


support for.\nFor each module we provide some examples to get started, how-to guides, reference docs, and conceptual guides.\nThese modules are, in increasing order of complexity:\n\nPrompts: This includes prompt management, prompt optimization, and prompt serialization.\nLLMs: This includes a generic interface for all LLMs, and common utilities for working with LLMs.\nDocument Loaders: This includes a standard interface for loading documents, as well as specific integrations to all types of text data sources.\nUtils: Language models are often more powerful when interacting with other sources of knowledge or computation. This can include Python REPLs, embeddings, search engines, and more. LangChain provides a large collection of common utils to use in your application.\nChains: Chains go beyond just a single LLM call, and are sequences of calls (whether to an LLM or a different utility). LangChain provides a standard interface for chains, lots of integrations with other tools, and end-to-end chains for common applications.\nIndexes: Language models are often more powerful when combined with your own


models are often more powerful when combined with your own text data - this module covers best practices for doing exactly that.\nAgents: Agents involve an LLM making decisions about which Actions to take, taking that Action, seeing an Observation, and repeating that until done. LangChain provides a standard interface for agents, a selection of agents to choose from, and examples of end to end agents.\nMemory: Memory is the concept of persisting state between calls of a chain/agent. LangChain provides a standard interface for memory, a collection of memory implementations, and examples of chains/agents that use memory.\nChat: Chat models are a variation on Language Models that expose a different API - rather than working with raw text, they work with messages. LangChain provides a standard interface for working with them and doing all the same things as above.\n\n\n\n\n\nUse Cases#\nThe above modules can be used in a variety of ways. LangChain also provides guidance and assistance in this. Below are some of the common use cases LangChain supports.\n\nAgents: Agents


the common use cases LangChain supports.\n\nAgents: Agents are systems that use a language model to interact with other tools. These can be used to do more grounded question/answering, interact with APIs, or even take actions.\nChatbots: Since language models are good at producing text, that makes them ideal for creating chatbots.\nData Augmented Generation: Data Augmented Generation involves specific types of chains that first interact with an external datasource to fetch data to use in the generation step. Examples of this include summarization of long pieces of text and question/answering over specific data sources.\nQuestion Answering: Answering questions over specific documents, only utilizing the information in those documents to construct an answer. A type of Data Augmented Generation.\nSummarization: Summarizing longer documents into shorter, more condensed chunks of information. A type of Data Augmented Generation.\nQuerying Tabular Data: If you want to understand how to use LLMs to query data that is stored in a tabular format (csvs, SQL, dataframes, etc) you should read this


SQL, dataframes, etc) you should read this page.\nEvaluation: Generative models are notoriously hard to evaluate with traditional metrics. One new way of evaluating them is using language models themselves to do the evaluation. LangChain provides some prompts/chains for assisting in this.\nGenerate similar examples: Generating similar examples to a given input. This is a common use case for many applications, and LangChain provides some prompts/chains for assisting in this.\nCompare models: Experimenting with different prompts, models, and chains is a big part of developing the best possible application. The ModelLaboratory makes it easy to do so.\n\n\n\n\n\nReference Docs#\nAll of LangChain’s reference documentation, in one place. Full documentation on all methods, classes, installation methods, and integration setups for LangChain.\n\nReference Documentation\n\n\n\n\n\nLangChain Ecosystem#\nGuides for how other companies/products can be used with LangChain\n\nLangChain Ecosystem\n\n\n\n\n\nAdditional Resources#\nAdditional collection of resources we think may be useful as you develop your application!\n\nLangChainHub: The LangChainHub is a place


application!\n\nLangChainHub: The LangChainHub is a place to share and explore other prompts, chains, and agents.\nGlossary: A glossary of all related terms, papers, methods, etc. Whether implemented in LangChain or not!\nGallery: A collection of our favorite projects that use LangChain. Useful for finding inspiration or seeing how things were done in other applications.\nDeployments: A collection of instructions, code snippets, and template repositories for deploying LangChain apps.\nDiscord: Join us on our Discord to discuss all things LangChain!\nTracing: A guide on using tracing in LangChain to visualize the execution of chains and agents.\nProduction Support: As you move your LangChains into production, we’d love to offer more comprehensive support. Please fill out this form and we’ll set up a dedicated support Slack channel.\n\n\n\n\n\n\n\n\n\n\n\nnext\nQuickstart Guide\n\n\n\n\n\n\n\n\n\n Contents\n  \n\n\nGetting Started\nModules\nUse Cases\nReference Docs\nLangChain Ecosystem\nAdditional Resources\n\n\n\n\n\n\n\n\n\nBy Harrison Chase\n\n\n\n\n    \n


Harrison Chase\n\n\n\n\n    \n      © Copyright 2023, Harrison Chase.\n      \n\n\n\n\n  Last updated on Mar 24, 2023.\n  \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n', lookup_str='', metadata={'source': 'https://python.langchain.com/en/stable/', 'loc': 'https://python.langchain.com/en/stable/', 'lastmod': '2023-03-24T19:30:54.647430+00:00', 'changefreq': 'weekly', 'priority': '1'}, lookup_index=0)


Filtering sitemap URLs#
Sitemaps can be massive files, with thousands of urls.  Often you don’t need every single one of them.  You can filter the urls by passing a list of strings or regex patterns to the url_filter parameter.  Only urls that match one of the patterns will be loaded.
loader = SitemapLoader(
    "https://langchain.readthedocs.io/sitemap.xml",
    filter_urls=["https://python.langchain.com/en/latest/"]
)
documents = loader.load()
documents[0]


Document(page_content='\n\n\n\n\n\nWelcome to LangChain — 🦜🔗 LangChain 0.0.123\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nSkip to main content\n\n\n\n\n\n\n\n\n\n\nCtrl+K\n\n\n\n\n\n\n\n\n\n\n\n\n🦜🔗 LangChain 0.0.123\n\n\n\nGetting Started\n\nQuickstart Guide\n\nModules\n\nModels\nLLMs\nGetting Started\nGeneric Functionality\nHow to use the async API for LLMs\nHow to write a custom LLM wrapper\nHow (and why) to use the fake LLM\nHow to cache LLM calls\nHow to serialize LLM classes\nHow to stream LLM responses\nHow to track token usage\n\n\nIntegrations\nAI21\nAleph Alpha\nAnthropic\nAzure OpenAI LLM Example\nBanana\nCerebriumAI LLM Example\nCohere\nDeepInfra LLM Example\nForefrontAI LLM Example\nGooseAI LLM Example\nHugging Face Hub\nManifest\nModal\nOpenAI\nPetals LLM Example\nPromptLayer OpenAI\nSageMakerEndpoint\nSelf-Hosted Models via Runhouse\nStochasticAI\nWriter\n\n\nReference\n\n\nChat Models\nGetting Started\nHow-To Guides\nHow


Models\nGetting Started\nHow-To Guides\nHow to use few shot examples\nHow to stream responses\n\n\nIntegrations\nAzure\nOpenAI\nPromptLayer ChatOpenAI\n\n\n\n\nText Embedding Models\nAzureOpenAI\nCohere\nFake Embeddings\nHugging Face Hub\nInstructEmbeddings\nOpenAI\nSageMaker Endpoint Embeddings\nSelf Hosted Embeddings\nTensorflowHub\n\n\n\n\nPrompts\nPrompt Templates\nGetting Started\nHow-To Guides\nHow to create a custom prompt template\nHow to create a prompt template that uses few shot examples\nHow to work with partial Prompt Templates\nHow to serialize prompts\n\n\nReference\nPromptTemplates\nExample Selector\n\n\n\n\nChat Prompt Template\nExample Selectors\nHow to create a custom example selector\nLengthBased ExampleSelector\nMaximal Marginal Relevance ExampleSelector\nNGram Overlap ExampleSelector\nSimilarity ExampleSelector\n\n\nOutput Parsers\nOutput Parsers\nCommaSeparatedListOutputParser\nOutputFixingParser\nPydanticOutputParser\nRetryOutputParser\nStructured Output Parser\n\n\n\n\nIndexes\nGetting Started\nDocument Loaders\nCoNLL-U\nAirbyte JSON\nAZLyrics\nBlackboard\nCollege Confidential\nCopy Paste\nCSV Loader\nDirectory Loader\nEmail\nEverNote\nFacebook Chat\nFigma\nGCS Directory\nGCS File Storage\nGitBook\nGoogle Drive\nGutenberg\nHacker


File Storage\nGitBook\nGoogle Drive\nGutenberg\nHacker News\nHTML\niFixit\nImages\nIMSDb\nMarkdown\nNotebook\nNotion\nObsidian\nPDF\nPowerPoint\nReadTheDocs Documentation\nRoam\ns3 Directory\ns3 File\nSubtitle Files\nTelegram\nUnstructured File Loader\nURL\nWeb Base\nWord Documents\nYouTube\n\n\nText Splitters\nGetting Started\nCharacter Text Splitter\nHuggingFace Length Function\nLatex Text Splitter\nMarkdown Text Splitter\nNLTK Text Splitter\nPython Code Text Splitter\nRecursiveCharacterTextSplitter\nSpacy Text Splitter\ntiktoken (OpenAI) Length Function\nTiktokenText Splitter\n\n\nVectorstores\nGetting Started\nAtlasDB\nChroma\nDeep Lake\nElasticSearch\nFAISS\nMilvus\nOpenSearch\nPGVector\nPinecone\nQdrant\nRedis\nWeaviate\n\n\nRetrievers\nChatGPT Plugin Retriever\nVectorStore Retriever\n\n\n\n\nMemory\nGetting Started\nHow-To Guides\nConversationBufferMemory\nConversationBufferWindowMemory\nEntity Memory\nConversation Knowledge Graph Memory\nConversationSummaryMemory\nConversationSummaryBufferMemory\nConversationTokenBufferMemory\nHow to add Memory to an LLMChain\nHow to add memory to a Multi-Input Chain\nHow to add Memory to an Agent\nHow to customize conversational memory\nHow to create a custom Memory class\nHow to use multiple memroy classes in the


Memory class\nHow to use multiple memroy classes in the same chain\n\n\n\n\nChains\nGetting Started\nHow-To Guides\nAsync API for Chain\nLoading from LangChainHub\nLLM Chain\nSequential Chains\nSerialization\nTransformation Chain\nAnalyze Document\nChat Index\nGraph QA\nHypothetical Document Embeddings\nQuestion Answering with Sources\nQuestion Answering\nSummarization\nRetrieval Question/Answering\nRetrieval Question Answering with Sources\nVector DB Text Generation\nAPI Chains\nSelf-Critique Chain with Constitutional AI\nBashChain\nLLMCheckerChain\nLLM Math\nLLMRequestsChain\nLLMSummarizationCheckerChain\nModeration\nPAL\nSQLite example\n\n\nReference\n\n\nAgents\nGetting Started\nTools\nGetting Started\nDefining Custom Tools\nMulti Input Tools\nBash\nBing Search\nChatGPT Plugins\nGoogle Search\nGoogle Serper API\nHuman as a tool\nIFTTT WebHooks\nPython REPL\nRequests\nSearch Tools\nSearxNG Search API\nSerpAPI\nWolfram Alpha\nZapier Natural Language Actions API\n\n\nAgents\nAgent Types\nCustom Agent\nConversation Agent (for Chat Models)\nConversation Agent\nMRKL\nMRKL Chat\nReAct\nSelf Ask With Search\n\n\nToolkits\nCSV Agent\nJSON Agent\nOpenAPI Agent\nPandas Dataframe Agent\nPython Agent\nSQL Database Agent\nVectorstore


Dataframe Agent\nPython Agent\nSQL Database Agent\nVectorstore Agent\n\n\nAgent Executors\nHow to combine agents and vectorstores\nHow to use the async API for Agents\nHow to create ChatGPT Clone\nHow to access intermediate steps\nHow to cap the max number of iterations\nHow to add SharedMemory to an Agent and its Tools\n\n\n\n\n\nUse Cases\n\nPersonal Assistants\nQuestion Answering over Docs\nChatbots\nQuerying Tabular Data\nInteracting with APIs\nSummarization\nExtraction\nEvaluation\nAgent Benchmarking: Search + Calculator\nAgent VectorDB Question Answering Benchmarking\nBenchmarking Template\nData Augmented Question Answering\nUsing Hugging Face Datasets\nLLM Math\nQuestion Answering Benchmarking: Paul Graham Essay\nQuestion Answering Benchmarking: State of the Union Address\nQA Generation\nQuestion Answering\nSQL Question Answering Benchmarking: Chinook\n\n\n\nReference\n\nInstallation\nIntegrations\nAPI References\nPrompts\nPromptTemplates\nExample Selector\n\n\nUtilities\nPython REPL\nSerpAPI\nSearxNG Search\nDocstore\nText Splitter\nEmbeddings\nVectorStores\n\n\nChains\nAgents\n\n\n\nEcosystem\n\nLangChain Ecosystem\nAI21 Labs\nAtlasDB\nBanana\nCerebriumAI\nChroma\nCohere\nDeepInfra\nDeep


Lake\nForefrontAI\nGoogle Search Wrapper\nGoogle Serper Wrapper\nGooseAI\nGraphsignal\nHazy Research\nHelicone\nHugging Face\nMilvus\nModal\nNLPCloud\nOpenAI\nOpenSearch\nPetals\nPGVector\nPinecone\nPromptLayer\nQdrant\nRunhouse\nSearxNG Search API\nSerpAPI\nStochasticAI\nUnstructured\nWeights & Biases\nWeaviate\nWolfram Alpha Wrapper\nWriter\n\n\n\nAdditional Resources\n\nLangChainHub\nGlossary\nLangChain Gallery\nDeployments\nTracing\nDiscord\nProduction Support\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n.rst\n\n\n\n\n\n\n\n.pdf\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nWelcome to LangChain\n\n\n\n\n Contents \n\n\n\nGetting Started\nModules\nUse Cases\nReference Docs\nLangChain Ecosystem\nAdditional Resources\n\n\n\n\n\n\n\n\nWelcome to LangChain#\nLangChain is a framework for developing applications powered by language models. We believe that the most powerful and differentiated applications will not only call out to a language model via an API, but will also:\n\nBe data-aware: connect a language model to other sources of data\nBe agentic: allow a language model to interact


data\nBe agentic: allow a language model to interact with its environment\n\nThe LangChain framework is designed with the above principles in mind.\nThis is the Python specific portion of the documentation. For a purely conceptual guide to LangChain, see here. For the JavaScript documentation, see here.\n\nGetting Started#\nCheckout the below guide for a walkthrough of how to get started using LangChain to create an Language Model application.\n\nGetting Started Documentation\n\n\n\n\n\nModules#\nThere are several main modules that LangChain provides support for.\nFor each module we provide some examples to get started, how-to guides, reference docs, and conceptual guides.\nThese modules are, in increasing order of complexity:\n\nModels: The various model types and model integrations LangChain supports.\nPrompts: This includes prompt management, prompt optimization, and prompt serialization.\nMemory: Memory is the concept of persisting state between calls of a chain/agent. LangChain provides a standard interface for memory, a collection of memory implementations, and examples of chains/agents that use memory.\nIndexes: Language models are often


that use memory.\nIndexes: Language models are often more powerful when combined with your own text data - this module covers best practices for doing exactly that.\nChains: Chains go beyond just a single LLM call, and are sequences of calls (whether to an LLM or a different utility). LangChain provides a standard interface for chains, lots of integrations with other tools, and end-to-end chains for common applications.\nAgents: Agents involve an LLM making decisions about which Actions to take, taking that Action, seeing an Observation, and repeating that until done. LangChain provides a standard interface for agents, a selection of agents to choose from, and examples of end to end agents.\n\n\n\n\n\nUse Cases#\nThe above modules can be used in a variety of ways. LangChain also provides guidance and assistance in this. Below are some of the common use cases LangChain supports.\n\nPersonal Assistants: The main LangChain use case. Personal assistants need to take actions, remember interactions, and have knowledge about your data.\nQuestion Answering: The second


have knowledge about your data.\nQuestion Answering: The second big LangChain use case. Answering questions over specific documents, only utilizing the information in those documents to construct an answer.\nChatbots: Since language models are good at producing text, that makes them ideal for creating chatbots.\nQuerying Tabular Data: If you want to understand how to use LLMs to query data that is stored in a tabular format (csvs, SQL, dataframes, etc) you should read this page.\nInteracting with APIs: Enabling LLMs to interact with APIs is extremely powerful in order to give them more up-to-date information and allow them to take actions.\nExtraction: Extract structured information from text.\nSummarization: Summarizing longer documents into shorter, more condensed chunks of information. A type of Data Augmented Generation.\nEvaluation: Generative models are notoriously hard to evaluate with traditional metrics. One new way of evaluating them is using language models themselves to do the evaluation. LangChain provides some prompts/chains for assisting in this.\n\n\n\n\n\nReference Docs#\nAll


assisting in this.\n\n\n\n\n\nReference Docs#\nAll of LangChain’s reference documentation, in one place. Full documentation on all methods, classes, installation methods, and integration setups for LangChain.\n\nReference Documentation\n\n\n\n\n\nLangChain Ecosystem#\nGuides for how other companies/products can be used with LangChain\n\nLangChain Ecosystem\n\n\n\n\n\nAdditional Resources#\nAdditional collection of resources we think may be useful as you develop your application!\n\nLangChainHub: The LangChainHub is a place to share and explore other prompts, chains, and agents.\nGlossary: A glossary of all related terms, papers, methods, etc. Whether implemented in LangChain or not!\nGallery: A collection of our favorite projects that use LangChain. Useful for finding inspiration or seeing how things were done in other applications.\nDeployments: A collection of instructions, code snippets, and template repositories for deploying LangChain apps.\nTracing: A guide on using tracing in LangChain to visualize the execution of chains and agents.\nModel Laboratory: Experimenting with different prompts, models, and chains is a big part of


prompts, models, and chains is a big part of developing the best possible application. The ModelLaboratory makes it easy to do so.\nDiscord: Join us on our Discord to discuss all things LangChain!\nProduction Support: As you move your LangChains into production, we’d love to offer more comprehensive support. Please fill out this form and we’ll set up a dedicated support Slack channel.\n\n\n\n\n\n\n\n\n\n\n\nnext\nQuickstart Guide\n\n\n\n\n\n\n\n\n\n Contents\n  \n\n\nGetting Started\nModules\nUse Cases\nReference Docs\nLangChain Ecosystem\nAdditional Resources\n\n\n\n\n\n\n\n\n\nBy Harrison Chase\n\n\n\n\n    \n      © Copyright 2023, Harrison Chase.\n      \n\n\n\n\n  Last updated on Mar 27, 2023.\n  \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n', lookup_str='', metadata={'source': 'https://python.langchain.com/en/latest/', 'loc': 'https://python.langchain.com/en/latest/', 'lastmod': '2023-03-27T22:50:49.790324+00:00', 'changefreq': 'daily', 'priority': '0.9'}, lookup_index=0)


previous
s3 File
next
Slack (Local Exported Zipfile)
 Contents

Filtering sitemap URLs
By Harrison Chase

      © Copyright 2023, Harrison Chase.

  Last updated on Apr 25, 2023.


.ipynb
.pdf
Getting Started
 Contents
Add texts
From Documents
Getting Started#
This notebook showcases basic functionality related to VectorStores. A key part of working with vectorstores is creating the vector to put in them, which is usually created via embeddings. Therefore, it is recommended that you familiarize yourself with the embedding notebook before diving into this.
This covers generic high level functionality related to all vector stores. For guides on specific vectorstores, please see the how-to guides here
from langchain.embeddings.openai import OpenAIEmbeddings
from langchain.text_splitter import CharacterTextSplitter
from langchain.vectorstores import Chroma
with open('../../state_of_the_union.txt') as f:
    state_of_the_union = f.read()
text_splitter = CharacterTextSplitter(chunk_size=1000, chunk_overlap=0)
texts = text_splitter.split_text(state_of_the_union)
embeddings = OpenAIEmbeddings()
docsearch = Chroma.from_texts(texts, embeddings)
query = "What did the president say about Ketanji Brown Jackson"
docs = docsearch.similarity_search(query)
Running Chroma using direct local API.
Using DuckDB in-memory for database. Data will be transient.
print(docs[0].page_content)
In state after state, new laws have been passed, not only to suppress the vote, but to subvert entire elections.
We cannot let this happen.
Tonight. I call on the Senate to: Pass the Freedom to Vote Act. Pass the John Lewis Voting Rights Act. And while you’re at it, pass the Disclose Act so Americans can know who is funding our elections.


Tonight, I’d like to honor someone who has dedicated his life to serve this country: Justice Stephen Breyer—an Army veteran, Constitutional scholar, and retiring Justice of the United States Supreme Court. Justice Breyer, thank you for your service.
One of the most serious constitutional responsibilities a President has is nominating someone to serve on the United States Supreme Court.
And I did that 4 days ago, when I nominated Circuit Court of Appeals Judge Ketanji Brown Jackson. One of our nation’s top legal minds, who will continue Justice Breyer’s legacy of excellence.
Add texts#
You can easily add text to a vectorstore with the add_texts method. It will return a list of document IDs (in case you need to use them downstream).
docsearch.add_texts(["Ankush went to Princeton"])
['a05e3d0c-ab40-11ed-a853-e65801318981']
query = "Where did Ankush go to college?"
docs = docsearch.similarity_search(query)
docs[0]
Document(page_content='Ankush went to Princeton', lookup_str='', metadata={}, lookup_index=0)
From Documents#
We can also initialize a vectorstore from documents directly. This is useful when we use the method on the text splitter to get documents directly (handy when the original documents have associated metadata).
documents = text_splitter.create_documents([state_of_the_union], metadatas=[{"source": "State of the Union"}])
docsearch = Chroma.from_documents(documents, embeddings)
query = "What did the president say about Ketanji Brown Jackson"
docs = docsearch.similarity_search(query)
Running Chroma using direct local API.
Using DuckDB in-memory for database. Data will be transient.
print(docs[0].page_content)


print(docs[0].page_content)
In state after state, new laws have been passed, not only to suppress the vote, but to subvert entire elections.
We cannot let this happen.
Tonight. I call on the Senate to: Pass the Freedom to Vote Act. Pass the John Lewis Voting Rights Act. And while you’re at it, pass the Disclose Act so Americans can know who is funding our elections.
Tonight, I’d like to honor someone who has dedicated his life to serve this country: Justice Stephen Breyer—an Army veteran, Constitutional scholar, and retiring Justice of the United States Supreme Court. Justice Breyer, thank you for your service.
One of the most serious constitutional responsibilities a President has is nominating someone to serve on the United States Supreme Court.
And I did that 4 days ago, when I nominated Circuit Court of Appeals Judge Ketanji Brown Jackson. One of our nation’s top legal minds, who will continue Justice Breyer’s legacy of excellence.
previous
Vectorstores
next
AnalyticDB
 Contents

Add texts
From Documents
By Harrison Chase

      © Copyright 2023, Harrison Chase.

  Last updated on Apr 25, 2023.


.ipynb
.pdf
Pinecone
Pinecone#
This notebook shows how to use functionality related to the Pinecone vector database.
from langchain.embeddings.openai import OpenAIEmbeddings
from langchain.text_splitter import CharacterTextSplitter
from langchain.vectorstores import Pinecone
from langchain.document_loaders import TextLoader
from langchain.document_loaders import TextLoader
loader = TextLoader('../../../state_of_the_union.txt')
documents = loader.load()
text_splitter = CharacterTextSplitter(chunk_size=1000, chunk_overlap=0)
docs = text_splitter.split_documents(documents)
embeddings = OpenAIEmbeddings()
import pinecone
# initialize pinecone
pinecone.init(
    api_key="YOUR_API_KEY",  # find at app.pinecone.io
    environment="YOUR_ENV"  # next to api key in console
)
index_name = "langchain-demo"
docsearch = Pinecone.from_documents(docs, embeddings, index_name=index_name)
# if you already have an index, you can load it like this
# docsearch = Pinecone.from_existing_index(index_name, embeddings)
query = "What did the president say about Ketanji Brown Jackson"
docs = docsearch.similarity_search(query)
print(docs[0].page_content)
previous
PGVector
next
Qdrant
By Harrison Chase

      © Copyright 2023, Harrison Chase.

  Last updated on Apr 25, 2023.


.ipynb
.pdf
Zilliz
Zilliz#
This notebook shows how to use functionality related to the Zilliz Cloud managed vector database.
To run, you should have a Zilliz Cloud instance up and running: https://zilliz.com/cloud
from langchain.embeddings.openai import OpenAIEmbeddings
from langchain.text_splitter import CharacterTextSplitter
from langchain.vectorstores import Milvus
from langchain.document_loaders import TextLoader
# replace
ZILLIZ_CLOUD_HOSTNAME = "" # example: "in01-17f69c292d4a50a.aws-us-west-2.vectordb.zillizcloud.com"
ZILLIZ_CLOUD_PORT = "" #example: "19532"
from langchain.document_loaders import TextLoader
loader = TextLoader('../../../state_of_the_union.txt')
documents = loader.load()
text_splitter = CharacterTextSplitter(chunk_size=1000, chunk_overlap=0)
docs = text_splitter.split_documents(documents)
embeddings = OpenAIEmbeddings()
vector_db = Milvus.from_documents(
    docs,
    embeddings,
    connection_args={"host": ZILLIZ_CLOUD_HOSTNAME, "port": ZILLIZ_CLOUD_PORT},
)
docs = vector_db.similarity_search(query)
docs[0]
previous
Weaviate
next
Retrievers
By Harrison Chase

      © Copyright 2023, Harrison Chase.

  Last updated on Apr 25, 2023.


.ipynb
.pdf
Qdrant
 Contents
Connecting to Qdrant from LangChain
Local mode
In-memory
On-disk storage
On-premise server deployment
Qdrant Cloud
Reusing the same collection
Similarity search
Similarity search with score
Maximum marginal relevance search (MMR)
Qdrant as a Retriever
Customizing Qdrant
Qdrant#
This notebook shows how to use functionality related to the Qdrant vector database. There are various modes of how to run Qdrant, and depending on the chosen one, there will be some subtle differences. The options include:
Local mode, no server required
On-premise server deployment
Qdrant Cloud
from langchain.embeddings.openai import OpenAIEmbeddings
from langchain.text_splitter import CharacterTextSplitter
from langchain.vectorstores import Qdrant
from langchain.document_loaders import TextLoader
loader = TextLoader('../../../state_of_the_union.txt')
documents = loader.load()
text_splitter = CharacterTextSplitter(chunk_size=1000, chunk_overlap=0)
docs = text_splitter.split_documents(documents)
embeddings = OpenAIEmbeddings()
Connecting to Qdrant from LangChain#
Local mode#
Python client allows you to run the same code in local mode without running the Qdrant server. That’s great for testing things out and debugging or if you plan to store just a small amount of vectors. The embeddings might be fully kepy in memory or persisted on disk.
In-memory#
For some testing scenarios and quick experiments, you may prefer to keep all the data in memory only, so it gets lost when the client is destroyed - usually at the end of your script/notebook.
qdrant = Qdrant.from_documents(
    docs, embeddings,


qdrant = Qdrant.from_documents(
    docs, embeddings,
    location=":memory:",  # Local mode with in-memory storage only
    collection_name="my_documents",
)
On-disk storage#
Local mode, without using the Qdrant server, may also store your vectors on disk so they’re persisted between runs.
qdrant = Qdrant.from_documents(
    docs, embeddings,
    path="/tmp/local_qdrant",
    collection_name="my_documents",
)
On-premise server deployment#
No matter if you choose to launch Qdrant locally with a Docker container, or select a Kubernetes deployment with the official Helm chart, the way you’re going to connect to such an instance will be identical. You’ll need to provide a URL pointing to the service.
url = "<---qdrant url here --->"
qdrant = Qdrant.from_documents(
    docs, embeddings,
    url, prefer_grpc=True,
    collection_name="my_documents",
)
Qdrant Cloud#
If you prefer not to keep yourself busy with managing the infrastructure, you can choose to set up a fully-managed Qdrant cluster on Qdrant Cloud. There is a free forever 1GB cluster included for trying out. The main difference with using a managed version of Qdrant is that you’ll need to provide an API key to secure your deployment from being accessed publicly.
url = "<---qdrant cloud cluster url here --->"
api_key = "<---api key here--->"
qdrant = Qdrant.from_documents(
    docs, embeddings,
    url, prefer_grpc=True, api_key=api_key,
    collection_name="my_documents",
)
Reusing the same collection#


collection_name="my_documents",
)
Reusing the same collection#
Both Qdrant.from_texts and Qdrant.from_documents methods are great to start using Qdrant with LangChain, but they are going to destroy the collection and create it from scratch! If you want to reuse the existing collection, you can always create an instance of Qdrant on your own and pass the QdrantClient instance with the connection details.
del qdrant
import qdrant_client
client = qdrant_client.QdrantClient(
    path="/tmp/local_qdrant", prefer_grpc=True
)
qdrant = Qdrant(
    client=client, collection_name="my_documents",
    embedding_function=embeddings.embed_query
)
Similarity search#
The simplest scenario for using Qdrant vector store is to perform a similarity search. Under the hood, our query will be encoded with the embedding_function and used to find similar documents in Qdrant collection.
query = "What did the president say about Ketanji Brown Jackson"
found_docs = qdrant.similarity_search(query)
print(found_docs[0].page_content)
Tonight. I call on the Senate to: Pass the Freedom to Vote Act. Pass the John Lewis Voting Rights Act. And while you’re at it, pass the Disclose Act so Americans can know who is funding our elections.
Tonight, I’d like to honor someone who has dedicated his life to serve this country: Justice Stephen Breyer—an Army veteran, Constitutional scholar, and retiring Justice of the United States Supreme Court. Justice Breyer, thank you for your service.
One of the most serious constitutional responsibilities a President has is nominating someone to serve on the United States Supreme Court.


And I did that 4 days ago, when I nominated Circuit Court of Appeals Judge Ketanji Brown Jackson. One of our nation’s top legal minds, who will continue Justice Breyer’s legacy of excellence.
Similarity search with score#
Sometimes we might want to perform the search, but also obtain a relevancy score to know how good is a particular result.
query = "What did the president say about Ketanji Brown Jackson"
found_docs = qdrant.similarity_search_with_score(query)
document, score = found_docs[0]
print(document.page_content)
print(f"\nScore: {score}")
Tonight. I call on the Senate to: Pass the Freedom to Vote Act. Pass the John Lewis Voting Rights Act. And while you’re at it, pass the Disclose Act so Americans can know who is funding our elections.
Tonight, I’d like to honor someone who has dedicated his life to serve this country: Justice Stephen Breyer—an Army veteran, Constitutional scholar, and retiring Justice of the United States Supreme Court. Justice Breyer, thank you for your service.
One of the most serious constitutional responsibilities a President has is nominating someone to serve on the United States Supreme Court.
And I did that 4 days ago, when I nominated Circuit Court of Appeals Judge Ketanji Brown Jackson. One of our nation’s top legal minds, who will continue Justice Breyer’s legacy of excellence.
Score: 0.8153784913324512
Maximum marginal relevance search (MMR)#
If you’d like to look up for some similar documents, but you’d also like to receive diverse results, MMR is method you should consider. Maximal marginal relevance optimizes for similarity to query AND diversity among selected documents.
query = "What did the president say about Ketanji Brown Jackson"


query = "What did the president say about Ketanji Brown Jackson"
found_docs = qdrant.max_marginal_relevance_search(query, k=2, fetch_k=10)
for i, doc in enumerate(found_docs):
    print(f"{i + 1}.", doc.page_content, "\n")
1. Tonight. I call on the Senate to: Pass the Freedom to Vote Act. Pass the John Lewis Voting Rights Act. And while you’re at it, pass the Disclose Act so Americans can know who is funding our elections.
Tonight, I’d like to honor someone who has dedicated his life to serve this country: Justice Stephen Breyer—an Army veteran, Constitutional scholar, and retiring Justice of the United States Supreme Court. Justice Breyer, thank you for your service.
One of the most serious constitutional responsibilities a President has is nominating someone to serve on the United States Supreme Court.
And I did that 4 days ago, when I nominated Circuit Court of Appeals Judge Ketanji Brown Jackson. One of our nation’s top legal minds, who will continue Justice Breyer’s legacy of excellence.
2. We can’t change how divided we’ve been. But we can change how we move forward—on COVID-19 and other issues we must face together.
I recently visited the New York City Police Department days after the funerals of Officer Wilbert Mora and his partner, Officer Jason Rivera.
They were responding to a 9-1-1 call when a man shot and killed them with a stolen gun.
Officer Mora was 27 years old.
Officer Rivera was 22.
Both Dominican Americans who’d grown up on the same streets they later chose to patrol as police officers.


I spoke with their families and told them that we are forever in debt for their sacrifice, and we will carry on their mission to restore the trust and safety every community deserves.
I’ve worked on these issues a long time.
I know what works: Investing in crime preventionand community police officers who’ll walk the beat, who’ll know the neighborhood, and who can restore trust and safety.
Qdrant as a Retriever#
Qdrant, as all the other vector stores, is a LangChain Retriever, by using cosine similarity.
retriever = qdrant.as_retriever()
retriever
VectorStoreRetriever(vectorstore=<langchain.vectorstores.qdrant.Qdrant object at 0x7fc4e5720a00>, search_type='similarity', search_kwargs={})
It might be also specified to use MMR as a search strategy, instead of similarity.
retriever = qdrant.as_retriever(search_type="mmr")
retriever
VectorStoreRetriever(vectorstore=<langchain.vectorstores.qdrant.Qdrant object at 0x7fc4e5720a00>, search_type='mmr', search_kwargs={})
query = "What did the president say about Ketanji Brown Jackson"
retriever.get_relevant_documents(query)[0]


retriever.get_relevant_documents(query)[0]
Document(page_content='Tonight. I call on the Senate to: Pass the Freedom to Vote Act. Pass the John Lewis Voting Rights Act. And while you’re at it, pass the Disclose Act so Americans can know who is funding our elections. \n\nTonight, I’d like to honor someone who has dedicated his life to serve this country: Justice Stephen Breyer—an Army veteran, Constitutional scholar, and retiring Justice of the United States Supreme Court. Justice Breyer, thank you for your service. \n\nOne of the most serious constitutional responsibilities a President has is nominating someone to serve on the United States Supreme Court. \n\nAnd I did that 4 days ago, when I nominated Circuit Court of Appeals Judge Ketanji Brown Jackson. One of our nation’s top legal minds, who will continue Justice Breyer’s legacy of excellence.', metadata={'source': '../../../state_of_the_union.txt'})
Customizing Qdrant#
Qdrant stores your vector embeddings along with the optional JSON-like payload. Payloads are optional, but since LangChain assumes the embeddings are generated from the documents, we keep the context data, so you can extract the original texts as well.
By default, your document is going to be stored in the following payload structure:
{
    "page_content": "Lorem ipsum dolor sit amet",
    "metadata": {
        "foo": "bar"
    }
}
You can, however, decide to use different keys for the page content and metadata. That’s useful if you already have a collection that you’d like to reuse. You can always change the
Qdrant.from_documents(
    docs, embeddings,
    location=":memory:",
    collection_name="my_documents_2",
    content_payload_key="my_page_content_key",
    metadata_payload_key="my_meta",
)


metadata_payload_key="my_meta",
)
<langchain.vectorstores.qdrant.Qdrant at 0x7fc4e2baa230>
previous
Pinecone
next
Redis
 Contents

Connecting to Qdrant from LangChain
Local mode
In-memory
On-disk storage
On-premise server deployment
Qdrant Cloud
Reusing the same collection
Similarity search
Similarity search with score
Maximum marginal relevance search (MMR)
Qdrant as a Retriever
Customizing Qdrant
By Harrison Chase

      © Copyright 2023, Harrison Chase.

  Last updated on Apr 25, 2023.


.ipynb
.pdf
SupabaseVectorStore
 Contents
Similarity search with score
Retriever options
Maximal Marginal Relevance Searches
SupabaseVectorStore#
This notebook shows how to use Supabase and pgvector as your VectorStore.
To run this notebook, please ensure:
the pgvector extension is enabled
you have installed the supabase-py package
that you have created a match_documents function in your database
that you have a documents table in your public schema similar to the one below.
The following function determines cosine similarity, but you can adjust to your needs.
       -- Enable the pgvector extension to work with embedding vectors
       create extension vector;
       -- Create a table to store your documents
       create table documents (
       id bigserial primary key,
       content text, -- corresponds to Document.pageContent
       metadata jsonb, -- corresponds to Document.metadata
       embedding vector(1536) -- 1536 works for OpenAI embeddings, change if needed
       );
       CREATE FUNCTION match_documents(query_embedding vector(1536), match_count int)
           RETURNS TABLE(
               id bigint,
               content text,
               metadata jsonb,
               -- we return matched vectors to enable maximal marginal relevance searches
               embedding vector(1536),
               similarity float)
           LANGUAGE plpgsql
           AS $$
           # variable_conflict use_column
       BEGIN
           RETURN query
           SELECT
               id,
               content,
               metadata,
               embedding,
               1 -(documents.embedding <=> query_embedding) AS similarity
           FROM
               documents
           ORDER BY
               documents.embedding <=> query_embedding
           LIMIT match_count;
       END;
       $$;
# with pip
# !pip install supabase
# with conda


$$;
# with pip
# !pip install supabase
# with conda
# !conda install -c conda-forge supabase
# If you're storing your Supabase and OpenAI API keys in a .env file, you can load them with dotenv
from dotenv import load_dotenv
load_dotenv()
True
import os
from supabase.client import Client, create_client
supabase_url = os.environ.get("SUPABASE_URL")
supabase_key = os.environ.get("SUPABASE_SERVICE_KEY")
supabase: Client = create_client(supabase_url, supabase_key)
from langchain.embeddings.openai import OpenAIEmbeddings
from langchain.text_splitter import CharacterTextSplitter
from langchain.vectorstores import SupabaseVectorStore
from langchain.document_loaders import TextLoader
2023-04-19 20:12:28,593:INFO - NumExpr defaulting to 8 threads.
from langchain.document_loaders import TextLoader
loader = TextLoader("../../../state_of_the_union.txt")
documents = loader.load()
text_splitter = CharacterTextSplitter(chunk_size=1000, chunk_overlap=0)
docs = text_splitter.split_documents(documents)
embeddings = OpenAIEmbeddings()
# We're using the default `documents` table here. You can modify this by passing in a `table_name` argument to the `from_documents` method.
vector_store = SupabaseVectorStore.from_documents(
    docs, embeddings, client=supabase
)
query = "What did the president say about Ketanji Brown Jackson"
matched_docs = vector_store.similarity_search(query)
print(matched_docs[0].page_content)